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

h = [[] for i in range(n)]

for i in range(n):

    h[i] = int(eval(input()))

h.sort()



diff = [[] for i in range(n-1)]

for i in range(n-1):

    diff[i] = h[i+1]-h[i]



t = [[] for i in range(n-1)]

t[0] = diff[0]

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

    t[i] = t[i-1]+diff[i]

t = [0] + t



# print(h)

# print(diff)

# print(t)



ans = float("inf")

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

    a = t[i+k-1]-t[i]

    ans = min(ans, a)



print(ans)

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

h = [[] for i in range(n)]

for i in range(n):

    h[i] = int(eval(input()))

h.sort()



ans = float("inf")

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

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

    ans = min(ans, a)

print(ans)

n, k = list(map(int, input().split()))
h = [[] for i in range(n)]
for i in range(n):
    h[i] = int(eval(input()))
h.sort()
diff = [[] for i in range(n - 1)]
for i in range(n - 1):
    diff[i] = h[i + 1] - h[i]
t = [[] for i in range(n - 1)]
t[0] = diff[0]
for i in range(1, n - 1):
    t[i] = t[i - 1] + diff[i]
t = [0] + t
# print(h)
# print(diff)
# print(t)
ans = float("inf")
for i in range(n - k + 1):
    a = t[i + k - 1] - t[i]
    ans = min(ans, a)
print(ans)

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

-diff = [[] for i in range(n - 1)] -for i in range(n - 1): -    diff[i] = h[i + 1] - h[i] -t = [[] for i in range(n - 1)] -t[0] = diff[0] -for i in range(1, n - 1): -    t[i] = t[i - 1] + diff[i] -t = [0] + t -# print(h) -# print(diff) -# print(t) -    a = t[i + k - 1] - t[i] +    a = h[i + k - 1] - h[i]