import numpy as np



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

H = np.array(sorted([int(eval(input())) for _ in range(N)]))



diff = H[K-1:] - H[:-K+1]

print((diff.min()))



# coding: utf-8

import sys

import numpy as np



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



N, K = lr()

H = np.array([ir() for _ in range(N)])

H.sort()

Hdiff = H[K-1:] - H[:-(K-1)]

answer = Hdiff.min()

print(answer)

import numpy as np

N, K = list(map(int, input().split()))
H = np.array(sorted([int(eval(input())) for _ in range(N)]))
diff = H[K - 1 :] - H[: -K + 1]
print((diff.min()))

# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, K = lr()
H = np.array([ir() for _ in range(N)])
H.sort()
Hdiff = H[K - 1 :] - H[: -(K - 1)]
answer = Hdiff.min()
print(answer)

+# coding: utf-8 +import sys -N, K = list(map(int, input().split())) -H = np.array(sorted([int(eval(input())) for _ in range(N)])) -diff = H[K - 1 :] - H[: -K + 1] -print((diff.min())) +sr = lambda: sys.stdin.readline().rstrip() +ir = lambda: int(sr()) +lr = lambda: list(map(int, sr().split())) +N, K = lr() +H = np.array([ir() for _ in range(N)]) +H.sort() +Hdiff = H[K - 1 :] - H[: -(K - 1)] +answer = Hdiff.min() +print(answer)