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

h = []

d = [0 for _ in range(n)]

ans = float('inf')



for _ in range(n):

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

h = sorted(h)



for i in range(1, n):

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



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

    diff = d[i + k - 1] - d[i]

    ans = min(ans, diff)



print(ans)

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

h = []

ans = float('inf')



for _ in range(n):

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

h = sorted(h)



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

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

    ans = min(ans, diff)



print(ans)

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

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

-d = [0 for _ in range(n)] -for i in range(1, n): -    d[i] = d[i - 1] + h[i] - h[i - 1] -    diff = d[i + k - 1] - d[i] +    diff = h[i + k - 1] - h[i]