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

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

K = sorted(K)



result = 10 ** 10

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

  result = min([result, K[i+M-1]-K[i]])

  

print(result)
N, M = list(map(int, input().split()))

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

K = sorted(K)

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

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

-result = 10**10 -for i in range(N - M + 1): -    result = min([result, K[i + M - 1] - K[i]]) -print(result) +print((min([K[i + M - 1] - K[i] for i in range(N - M + 1)])))