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

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

ans = float('inf')

for i in range(N - K + 1):

    if abs(heights[i] - heights[i + K - 1]) < ans:

        ans = abs(heights[i] - heights[i + K - 1])

print(ans)
import sys

input = sys.stdin.readline

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

heights = sorted([int(input().rstrip()) for _ in range(N)])

ans = float('inf')

for i in range(N - K + 1):

    if abs(heights[i] - heights[i + K - 1]) < ans:

        ans = abs(heights[i] - heights[i + K - 1])

print(ans)
N, K = list(map(int, input().split()))
heights = sorted([int(eval(input())) for _ in range(N)])
ans = float("inf")
for i in range(N - K + 1):
    if abs(heights[i] - heights[i + K - 1]) < ans:
        ans = abs(heights[i] - heights[i + K - 1])
print(ans)

import sys

input = sys.stdin.readline
N, K = list(map(int, input().rstrip().split()))
heights = sorted([int(input().rstrip()) for _ in range(N)])
ans = float("inf")
for i in range(N - K + 1):
    if abs(heights[i] - heights[i + K - 1]) < ans:
        ans = abs(heights[i] - heights[i + K - 1])
print(ans)

-N, K = list(map(int, input().split())) -heights = sorted([int(eval(input())) for _ in range(N)]) +import sys + +input = sys.stdin.readline +N, K = list(map(int, input().rstrip().split())) +heights = sorted([int(input().rstrip()) for _ in range(N)])