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

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

h.sort()

between = [h[i+1]-h[i] for i in range(n-1)]

answer = 10**9

for i in range(1,n-1):

  between[i] += between[i-1]

between.insert(0,0)



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

  answer = min(answer, between[i+k-1]-between[i])

  

print(answer)
n, k, *h = list(map(int, open(0).read().split()))

h.sort()

ans = 10e9+7

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

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

print(ans)

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

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

-n, k = list(map(int, input().split())) -h = [int(eval(input())) for _ in range(n)] +n, k, *h = list(map(int, open(0).read().split())) -between = [h[i + 1] - h[i] for i in range(n - 1)] -answer = 10**9 -for i in range(1, n - 1): -    between[i] += between[i - 1] -between.insert(0, 0) +ans = 10e9 + 7 -    answer = min(answer, between[i + k - 1] - between[i]) -print(answer) +    ans = min(ans, h[i + k - 1] - h[i]) +print(ans)