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

h=[]

for i in range(n):

  h.append(int(eval(input())))



h.sort()

S=10000000000000

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

  if S>h[i+k-1]-h[i]:

    S=h[i+k-1]-h[i]

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

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

h.sort()

hantei=10**9+1

for i in range(len(h)-k+1):

  if (h[i+k-1]-h[i])<hantei:

    hantei=h[i+k-1]-h[i]

print(hantei)
n, k = list(map(int, input().split()))
h = []
for i in range(n):
    h.append(int(eval(input())))
h.sort()
S = 10000000000000
for i in range(n - k + 1):
    if S > h[i + k - 1] - h[i]:
        S = h[i + k - 1] - h[i]
print(S)

n, k = list(map(int, input().split()))
h = [int(eval(input())) for i in range(n)]
h.sort()
hantei = 10**9 + 1
for i in range(len(h) - k + 1):
    if (h[i + k - 1] - h[i]) < hantei:
        hantei = h[i + k - 1] - h[i]
print(hantei)

-h = [] -for i in range(n): -    h.append(int(eval(input()))) +h = [int(eval(input())) for i in range(n)] -S = 10000000000000 -for i in range(n - k + 1): -    if S > h[i + k - 1] - h[i]: -        S = h[i + k - 1] - h[i] -print(S) +hantei = 10**9 + 1 +for i in range(len(h) - k + 1): +    if (h[i + k - 1] - h[i]) < hantei: +        hantei = h[i + k - 1] - h[i] +print(hantei)