n,k = [int(item) for item in input().split()]

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



h = sorted(h)



diff_h = []

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

  diff_h.append(h[i+k-1] - h[i])

  

print((min(diff_h)))
#!/usr/bin/env python3

import sys

input = sys.stdin.readline



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

h = []

for _ in range(n):

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

h.sort()



min_diff = 10**9

for hl, hr in zip(h, h[k-1:]):

    min_diff = min(min_diff, hr - hl)

print(min_diff)
n, k = [int(item) for item in input().split()]
h = [int(eval(input())) for _ in range(n)]
h = sorted(h)
diff_h = []
for i in range(n - (k - 1)):
    diff_h.append(h[i + k - 1] - h[i])
print((min(diff_h)))

#!/usr/bin/env python3
import sys

input = sys.stdin.readline
n, k = list(map(int, input().split()))
h = []
for _ in range(n):
    h.append(int(eval(input())))
h.sort()
min_diff = 10**9
for hl, hr in zip(h, h[k - 1 :]):
    min_diff = min(min_diff, hr - hl)
print(min_diff)

-n, k = [int(item) for item in input().split()] -h = [int(eval(input())) for _ in range(n)] -h = sorted(h) -diff_h = [] -for i in range(n - (k - 1)): -    diff_h.append(h[i + k - 1] - h[i]) -print((min(diff_h))) +#!/usr/bin/env python3 +import sys + +input = sys.stdin.readline +n, k = list(map(int, input().split())) +h = [] +for _ in range(n): +    h.append(int(eval(input()))) +h.sort() +min_diff = 10**9 +for hl, hr in zip(h, h[k - 1 :]): +    min_diff = min(min_diff, hr - hl) +print(min_diff)