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

h=[]

for i in range(N):

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

h.sort()



d=10**10

for i in range(N-K+1):

  d=min(d,abs(h[i]-h[i+K-1]))



print(d)
import sys

input = sys.stdin.buffer.readline



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

H = [int(eval(input())) for _ in range(N)]



H.sort()



answer = 10 ** 15

for i in range(N - K + 1):

  answer = min(answer, H[i + K - 1] - H[i])



print(answer)
N, K = list(map(int, input().split()))
h = []
for i in range(N):
    h.append(int(eval(input())))
h.sort()
d = 10**10
for i in range(N - K + 1):
    d = min(d, abs(h[i] - h[i + K - 1]))
print(d)

import sys

input = sys.stdin.buffer.readline
N, K = list(map(int, input().split()))
H = [int(eval(input())) for _ in range(N)]
H.sort()
answer = 10**15
for i in range(N - K + 1):
    answer = min(answer, H[i + K - 1] - H[i])
print(answer)

+import sys + +input = sys.stdin.buffer.readline -h = [] -for i in range(N): -    h.append(int(eval(input()))) -h.sort() -d = 10**10 +H = [int(eval(input())) for _ in range(N)] +H.sort() +answer = 10**15 -    d = min(d, abs(h[i] - h[i + K - 1])) -print(d) +    answer = min(answer, H[i + K - 1] - H[i]) +print(answer)