n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
h = sorted(h)
H = []
for i in range(n - k + 1):
    H_i = h[i + k - 1] - h[i]
    H.append(H_i)
print(min(H))

b477f8cd0611798903748799c004591846b94fbe
<mask token>

<mask token>
for i in range(n - k + 1):
    H_i = h[i + k - 1] - h[i]
    H.append(H_i)
print(min(H))

n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
h = sorted(h)
H = []
for i in range(n - k + 1):
    H_i = h[i + k - 1] - h[i]
    H.append(H_i)
print(min(H))
