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

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



h.sort()

m = min(h[i + K - 1] - h[i] for i in range(N - K + 1))

print(m)
import sys



N, K, *h = list(map(int, sys.stdin.read().split()))



h.sort()

m = min(h[i + K - 1] - h[i] for i in range(N - K + 1))

print(m)
N, K = list(map(int, input().split()))
h = [int(eval(input())) for _ in range(N)]
h.sort()
m = min(h[i + K - 1] - h[i] for i in range(N - K + 1))
print(m)

import sys

N, K, *h = list(map(int, sys.stdin.read().split()))
h.sort()
m = min(h[i + K - 1] - h[i] for i in range(N - K + 1))
print(m)

-N, K = list(map(int, input().split())) -h = [int(eval(input())) for _ in range(N)] +import sys + +N, K, *h = list(map(int, sys.stdin.read().split()))