import sys

from collections import deque

input = sys.stdin.readline

import numpy as np

N, K = [int(x) for x in input().split()]

h = []

for _ in range(N):

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

h.sort()

i = 0

ans = []

while N - i >= K:

    temp = []

    temp.append(h[i])

    temp.append(h[i+K-1])

    ans.append(temp[-1] - temp[0])

    i += 1

print((min(ans)))
import sys

input = sys.stdin.readline

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

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

h.sort()

ans = 10 ** 10

for i in range(n):

    if i + k - 1 >= n:

        break

    ans = min(ans, h[i + k - 1] - h[i])

print(ans)

    
import sys
from collections import deque

input = sys.stdin.readline
import numpy as np

N, K = [int(x) for x in input().split()]
h = []
for _ in range(N):
    h.append(int(eval(input())))
h.sort()
i = 0
ans = []
while N - i >= K:
    temp = []
    temp.append(h[i])
    temp.append(h[i + K - 1])
    ans.append(temp[-1] - temp[0])
    i += 1
print((min(ans)))

import sys

input = sys.stdin.readline
n, k = [int(x) for x in input().split()]
h = [int(eval(input())) for _ in range(n)]
h.sort()
ans = 10**10
for i in range(n):
    if i + k - 1 >= n:
        break
    ans = min(ans, h[i + k - 1] - h[i])
print(ans)

-from collections import deque -import numpy as np - -N, K = [int(x) for x in input().split()] -h = [] -for _ in range(N): -    h.append(int(eval(input()))) +n, k = [int(x) for x in input().split()] +h = [int(eval(input())) for _ in range(n)] -i = 0 -ans = [] -while N - i >= K: -    temp = [] -    temp.append(h[i]) -    temp.append(h[i + K - 1]) -    ans.append(temp[-1] - temp[0]) -    i += 1 -print((min(ans))) +ans = 10**10 +for i in range(n): +    if i + k - 1 >= n: +        break +    ans = min(ans, h[i + k - 1] - h[i]) +print(ans)