n, k = list(map(int, input().split()))

H = [int(eval(input())) for _ in range(n)]

H = sorted(H)

ans = float('inf')

for i in range(n - k + 1):

    ans = min(ans, H[i + k - 1] - H[i])

print(ans)
def main():

    n, k = list(map(int, input().split()))

    H = [int(eval(input())) for _ in range(n)]

    H.sort()

    ans = 10 ** 9 + 2

    for i in range(n - k + 1):

        ans = min(ans, H[i + k - 1] - H[i])

    print(ans)



if __name__ == '__main__':

    main()

n, k = list(map(int, input().split()))
H = [int(eval(input())) for _ in range(n)]
H = sorted(H)
ans = float("inf")
for i in range(n - k + 1):
    ans = min(ans, H[i + k - 1] - H[i])
print(ans)

def main():
    n, k = list(map(int, input().split()))
    H = [int(eval(input())) for _ in range(n)]
    H.sort()
    ans = 10**9 + 2
    for i in range(n - k + 1):
        ans = min(ans, H[i + k - 1] - H[i])
    print(ans)


if __name__ == "__main__":
    main()

-n, k = list(map(int, input().split())) -H = [int(eval(input())) for _ in range(n)] -H = sorted(H) -ans = float("inf") -for i in range(n - k + 1): -    ans = min(ans, H[i + k - 1] - H[i]) -print(ans) +def main(): +    n, k = list(map(int, input().split())) +    H = [int(eval(input())) for _ in range(n)] +    H.sort() +    ans = 10**9 + 2 +    for i in range(n - k + 1): +        ans = min(ans, H[i + k - 1] - H[i]) +    print(ans) + + +if __name__ == "__main__": +    main()