N, K = list(map(int, input().split()))

trees = [int(eval(input())) for i in range(N)]

trees = sorted(trees)



result = min(trees[i+K-1] - trees[i] for i in range(N-K+1))



print(result)

N, K, *trees = list(map(int, open(0).read().split()))

trees = sorted(trees)

print((min(trees[i+K-1] - trees[i] for i in range(N-K+1))))

N, K = list(map(int, input().split()))
trees = [int(eval(input())) for i in range(N)]
trees = sorted(trees)
result = min(trees[i + K - 1] - trees[i] for i in range(N - K + 1))
print(result)

N, K, *trees = list(map(int, open(0).read().split()))
trees = sorted(trees)
print((min(trees[i + K - 1] - trees[i] for i in range(N - K + 1))))

-N, K = list(map(int, input().split())) -trees = [int(eval(input())) for i in range(N)] +N, K, *trees = list(map(int, open(0).read().split())) -result = min(trees[i + K - 1] - trees[i] for i in range(N - K + 1)) -print(result) +print((min(trees[i + K - 1] - trees[i] for i in range(N - K + 1))))