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



height = []

for _ in range(N) :

    height.append(int(eval(input())))



height.sort()

ans = float('inf')



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

    diff = height[i + K - 1] - height[i]

    ans = min(ans, diff)



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

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

H.sort()



ans = 10**18

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

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

print(ans)
N, K = list(map(int, input().split()))
height = []
for _ in range(N):
    height.append(int(eval(input())))
height.sort()
ans = float("inf")
for i in range(N - K + 1):
    diff = height[i + K - 1] - height[i]
    ans = min(ans, diff)
print(ans)

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

-height = [] -for _ in range(N): -    height.append(int(eval(input()))) -height.sort() -ans = float("inf") +H = [int(eval(input())) for _ in range(N)] +H.sort() +ans = 10**18 -    diff = height[i + K - 1] - height[i] -    ans = min(ans, diff) +    ans = min(ans, H[i + K - 1] - H[i])