n, k = list(map(int, input().split()))

height = [int(eval(input())) for _ in range(n)]

height.sort()

ans = height[-1]

for i in range(n-k+1):

    ans = min(ans, height[i+k-1]-height[i])

print(ans)
n, k, *height = list(map(int, open(0).read().split()))

height.sort()

ans = height[-1]

for i in range(n-k+1):

    ans = min(ans, height[i+k-1]-height[i])

print(ans)
n, k = list(map(int, input().split()))
height = [int(eval(input())) for _ in range(n)]
height.sort()
ans = height[-1]
for i in range(n - k + 1):
    ans = min(ans, height[i + k - 1] - height[i])
print(ans)

n, k, *height = list(map(int, open(0).read().split()))
height.sort()
ans = height[-1]
for i in range(n - k + 1):
    ans = min(ans, height[i + k - 1] - height[i])
print(ans)

-n, k = list(map(int, input().split())) -height = [int(eval(input())) for _ in range(n)] +n, k, *height = list(map(int, open(0).read().split()))