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

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



h.sort()

ans=10**18



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

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

print(ans)

import sys

input = sys.stdin.readline

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

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

H.sort()



ans = 10**18

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

    ans = min(ans, abs(H[i] - abs(H[i + K - 1])))



print(ans)

n, k = list(map(int, input().split()))
h = [int(eval(input())) for _ in range(n)]
h.sort()
ans = 10**18
for i in range(n - k + 1):
    ans = min(ans, h[i + k - 1] - h[i])
print(ans)

import sys

input = sys.stdin.readline
N, K = list(map(int, input().split()))
H = [int(eval(input())) for _ in range(N)]
H.sort()
ans = 10**18
for i in range(N - K + 1):
    ans = min(ans, abs(H[i] - abs(H[i + K - 1])))
print(ans)

-n, k = list(map(int, input().split())) -h = [int(eval(input())) for _ in range(n)] -h.sort() +import sys + +input = sys.stdin.readline +N, K = list(map(int, input().split())) +H = [int(eval(input())) for _ in range(N)] +H.sort() -for i in range(n - k + 1): -    ans = min(ans, h[i + k - 1] - h[i]) +for i in range(N - K + 1): +    ans = min(ans, abs(H[i] - abs(H[i + K - 1])))