import heapq



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

h = []

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

ans = float('inf')



for _ in range(n):

    heapq.heappush(h, int(eval(input())))



h = [heapq.heappop(h) for _ in range(n)]





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 = 1e9



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)

import heapq

n, k = list(map(int, input().split()))
h = []
d = [0 for _ in range(n)]
ans = float("inf")
for _ in range(n):
    heapq.heappush(h, int(eval(input())))
h = [heapq.heappop(h) for _ in range(n)]
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 = 1e9
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)

-import heapq - -ans = float("inf") +ans = 1e9 -    heapq.heappush(h, int(eval(input()))) -h = [heapq.heappop(h) for _ in range(n)] +    h.append(int(eval(input()))) +h = sorted(h)