# -*- coding: utf-8 -*-



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

H = []

for i in range(N):

    H.append(int(eval(input())))



H.sort()



ans = H[-1] - H[0]

for i in range(len(H) - K + 1):

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



print(ans)

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

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

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

# -*- coding: utf-8 -*-
N, K = list(map(int, input().split()))
H = []
for i in range(N):
    H.append(int(eval(input())))
H.sort()
ans = H[-1] - H[0]
for i in range(len(H) - K + 1):
    ans = min(ans, H[i + K - 1] - H[i])
print(ans)

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

-# -*- coding: utf-8 -*- -H = [] -for i in range(N): -    H.append(int(eval(input()))) -H.sort() -ans = H[-1] - H[0] -for i in range(len(H) - K + 1): -    ans = min(ans, H[i + K - 1] - H[i]) -print(ans) +H = sorted([int(eval(input())) for _ in range(N)]) +print((min([H[i + K - 1] - H[i] for i in range(N - K + 1)])))