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

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

H.sort()

tmax=10**9

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

    h1,h2=H[a],H[a+K-1]

    tmax=min(tmax,abs(h1-h2))

    if(tmax==0):

        break

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

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

H.sort()

tmp=H[K-1]-H[0]

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

    if tmp>H[K+i-1]-H[i]:

        tmp=H[K+i-1]-H[i]

print(tmp)
N, K = list(map(int, input().split(" ")))
H = [int(eval(input())) for _ in range(N)]
H.sort()
tmax = 10**9
for a in range(N - K + 1):
    h1, h2 = H[a], H[a + K - 1]
    tmax = min(tmax, abs(h1 - h2))
    if tmax == 0:
        break
print(tmax)

N, K = list(map(int, input().split()))
H = [int(eval(input())) for _ in range(N)]
H.sort()
tmp = H[K - 1] - H[0]
for i in range(0, N - K + 1):
    if tmp > H[K + i - 1] - H[i]:
        tmp = H[K + i - 1] - H[i]
print(tmp)

-N, K = list(map(int, input().split(" "))) +N, K = list(map(int, input().split())) -tmax = 10**9 -for a in range(N - K + 1): -    h1, h2 = H[a], H[a + K - 1] -    tmax = min(tmax, abs(h1 - h2)) -    if tmax == 0: -        break -print(tmax) +tmp = H[K - 1] - H[0] +for i in range(0, N - K + 1): +    if tmp > H[K + i - 1] - H[i]: +        tmp = H[K + i - 1] - H[i] +print(tmp)