INF = 1000000007



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

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



h.sort()



ans = INF



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

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



print(ans)

INF = 1000000007



N, K, *h = list(map(int, open(0).read().split()))



h.sort()



ans = INF



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

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



print(ans)

INF = 1000000007
N, K = list(map(int, input().split()))
h = [int(eval(input())) for i in range(N)]
h.sort()
ans = INF
for i in range(N - K + 1):
    ans = min(ans, h[i + K - 1] - h[i])
print(ans)

INF = 1000000007
N, K, *h = list(map(int, open(0).read().split()))
h.sort()
ans = INF
for i in range(N - K + 1):
    ans = min(ans, h[i + K - 1] - h[i])
print(ans)

-N, K = list(map(int, input().split())) -h = [int(eval(input())) for i in range(N)] +N, K, *h = list(map(int, open(0).read().split()))