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



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

list.sort()

min_val = 10**9

for i in range(N-K+1):

    min_val = min(min_val,list[i+K-1]-list[i])



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



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



list.sort()



init = max(list) - min(list)



diff = [b-a for a,b in zip(list,list[K-1::])]



print((min(diff)))
N, K = list(map(int, input().split()))
list = [int(eval(input())) for i in range(N)]
list.sort()
min_val = 10**9
for i in range(N - K + 1):
    min_val = min(min_val, list[i + K - 1] - list[i])
print(min_val)

N, K = list(map(int, input().split()))
list = [int(eval(input())) for i in range(N)]
list.sort()
init = max(list) - min(list)
diff = [b - a for a, b in zip(list, list[K - 1 : :])]
print((min(diff)))

-min_val = 10**9 -for i in range(N - K + 1): -    min_val = min(min_val, list[i + K - 1] - list[i]) -print(min_val) +init = max(list) - min(list) +diff = [b - a for a, b in zip(list, list[K - 1 : :])] +print((min(diff)))