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

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

H.sort()

ans = 10 ** 18

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

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

    ans = min(ans, tmp)

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):

    h1 = H[i]

    h2 = H[i + K - 1]

    ans = min(ans, h2 - h1)

print(ans)
N, K = list(map(int, input().split()))
H = list(int(eval(input())) for _ in range(N))
H.sort()
ans = 10**18
for i in range(N - K + 1):
    tmp = H[i + K - 1] - H[i]
    ans = min(ans, tmp)
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):
    h1 = H[i]
    h2 = H[i + K - 1]
    ans = min(ans, h2 - h1)
print(ans)

-H = list(int(eval(input())) for _ in range(N)) +H = [int(eval(input())) for _ in range(N)] -    tmp = H[i + K - 1] - H[i] -    ans = min(ans, tmp) +    h1 = H[i] +    h2 = H[i + K - 1] +    ans = min(ans, h2 - h1)