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

L = []

for i in range(N) :

    l = int(eval(input()))

    L.append(l)

L = sorted(L)

ans = 10**9+1

for i in range(len(L)-K+1) :

    mi = L[i]

    ma = L[i+K-1]

    di = ma - mi

    if di < ans :

        ans = di

print(ans)

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

L = sorted([int(eval(input())) for i in range(N)])

ans = float("inf")

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

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

print(ans)

N, K = list(map(int, input().split()))
L = []
for i in range(N):
    l = int(eval(input()))
    L.append(l)
L = sorted(L)
ans = 10**9 + 1
for i in range(len(L) - K + 1):
    mi = L[i]
    ma = L[i + K - 1]
    di = ma - mi
    if di < ans:
        ans = di
print(ans)

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

-L = [] -for i in range(N): -    l = int(eval(input())) -    L.append(l) -L = sorted(L) -ans = 10**9 + 1 -for i in range(len(L) - K + 1): -    mi = L[i] -    ma = L[i + K - 1] -    di = ma - mi -    if di < ans: -        ans = di +L = sorted([int(eval(input())) for i in range(N)]) +ans = float("inf") +for i in range(N - K + 1): +    ans = min(ans, L[i + K - 1] - L[i])