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

heights = []

for _ in range(n):

    heights.append(int(eval(input())))



heights.sort()



ans = float('inf')

for i in range(len(heights)):

    if i + k - 1 >= len(heights):

        break

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



print(ans)

import os

import sys



import numpy as np



if os.getenv("LOCAL"):

    sys.stdin = open("_in.txt", "r")



sys.setrecursionlimit(10 ** 9)

INF = float("inf")

IINF = 10 ** 18

MOD = 10 ** 9 + 7

# MOD = 998244353





N, K = list(map(int, sys.stdin.buffer.readline().split()))

H = [int(sys.stdin.buffer.readline()) for _ in range(N)]



H = np.array(H, dtype=int)



H.sort()

d = N - K + 1

a = H[-d:] - H[:d]

print((a.min()

      ))

n, k = list(map(int, input().split()))
heights = []
for _ in range(n):
    heights.append(int(eval(input())))
heights.sort()
ans = float("inf")
for i in range(len(heights)):
    if i + k - 1 >= len(heights):
        break
    ans = min(ans, heights[i + k - 1] - heights[i])
print(ans)

import os
import sys
import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10**9)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
# MOD = 998244353
N, K = list(map(int, sys.stdin.buffer.readline().split()))
H = [int(sys.stdin.buffer.readline()) for _ in range(N)]
H = np.array(H, dtype=int)
H.sort()
d = N - K + 1
a = H[-d:] - H[:d]
print((a.min()))

-n, k = list(map(int, input().split())) -heights = [] -for _ in range(n): -    heights.append(int(eval(input()))) -heights.sort() -ans = float("inf") -for i in range(len(heights)): -    if i + k - 1 >= len(heights): -        break -    ans = min(ans, heights[i + k - 1] - heights[i]) -print(ans) +import os +import sys +import numpy as np + +if os.getenv("LOCAL"): +    sys.stdin = open("_in.txt", "r") +sys.setrecursionlimit(10**9) +INF = float("inf") +IINF = 10**18 +MOD = 10**9 + 7 +# MOD = 998244353 +N, K = list(map(int, sys.stdin.buffer.readline().split())) +H = [int(sys.stdin.buffer.readline()) for _ in range(N)] +H = np.array(H, dtype=int) +H.sort() +d = N - K + 1 +a = H[-d:] - H[:d] +print((a.min()))