from collections import deque

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

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

x = deque([])

mn = 10**9

for i in h:

    x.append(i)

    if len(x) >= k:

        mn = min(mn,x[k-1]-x[0])

        x.popleft()

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

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

mn = 10**9

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

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

print(mn)
from collections import deque

n, k = list(map(int, input().split()))
h = sorted([int(eval(input())) for _ in range(n)])
x = deque([])
mn = 10**9
for i in h:
    x.append(i)
    if len(x) >= k:
        mn = min(mn, x[k - 1] - x[0])
        x.popleft()
print(mn)

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

-from collections import deque - -x = deque([]) -for i in h: -    x.append(i) -    if len(x) >= k: -        mn = min(mn, x[k - 1] - x[0]) -        x.popleft() +for i in range(n - k + 1): +    mn = min(mn, h[i + k - 1] - h[i])