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



tree = []

for _ in range(n):

    tree.append(int(eval(input())))



tree.sort()

ans = 10**9

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

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

print(ans)

import sys

sys.setrecursionlimit(10 ** 6)





def input():

    return sys.stdin.readline()[:-1]





N, K = list(map(int, input().split()))

H = [0]*N

for i in range(N):

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



H.sort()

ans = 10**10

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()))
tree = []
for _ in range(n):
    tree.append(int(eval(input())))
tree.sort()
ans = 10**9
for i in range(n - k + 1):
    ans = min(ans, tree[i + k - 1] - tree[i])
print(ans)

import sys

sys.setrecursionlimit(10**6)


def input():
    return sys.stdin.readline()[:-1]


N, K = list(map(int, input().split()))
H = [0] * N
for i in range(N):
    H[i] = int(eval(input()))
H.sort()
ans = 10**10
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())) -tree = [] -for _ in range(n): -    tree.append(int(eval(input()))) -tree.sort() -ans = 10**9 -for i in range(n - k + 1): -    ans = min(ans, tree[i + k - 1] - tree[i]) +import sys + +sys.setrecursionlimit(10**6) + + +def input(): +    return sys.stdin.readline()[:-1] + + +N, K = list(map(int, input().split())) +H = [0] * N +for i in range(N): +    H[i] = int(eval(input())) +H.sort() +ans = 10**10 +for i in range(N - (K - 1)): +    ans = min(ans, H[i + (K - 1)] - H[i])