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

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

h = sorted(h)



d = float('inf')

i = 0

while i + k - 1 < n:

    d = min(h[i + k - 1] - h[i], d)

    i += 1



print(d)

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

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

h = sorted(h)

print((min(h[i + k - 1] - h[i] for i in range(n - k + 1))))

n, k = list(map(int, input().split()))
h = [int(eval(input())) for _ in range(n)]
h = sorted(h)
d = float("inf")
i = 0
while i + k - 1 < n:
    d = min(h[i + k - 1] - h[i], d)
    i += 1
print(d)

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

-d = float("inf") -i = 0 -while i + k - 1 < n: -    d = min(h[i + k - 1] - h[i], d) -    i += 1 -print(d) +print((min(h[i + k - 1] - h[i] for i in range(n - k + 1))))