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

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

hhh.sort()

ans = float('inf')

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

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

print(ans)

from itertools import starmap

from operator import sub



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

hhh = sorted(int(eval(input())) for _ in range(n))

print((min(starmap(sub, list(zip(hhh[k - 1:], hhh))))))

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

from itertools import starmap
from operator import sub

n, k = list(map(int, input().split()))
hhh = sorted(int(eval(input())) for _ in range(n))
print((min(starmap(sub, list(zip(hhh[k - 1 :], hhh))))))

+from itertools import starmap +from operator import sub + -hhh = [int(eval(input())) for _ in range(n)] -hhh.sort() -ans = float("inf") -for i in range(n - k + 1): -    ans = min(ans, hhh[i + k - 1] - hhh[i]) -print(ans) +hhh = sorted(int(eval(input())) for _ in range(n)) +print((min(starmap(sub, list(zip(hhh[k - 1 :], hhh))))))