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

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

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