from collections import Counter



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

H = []

for i in range(N):

    H.append(int(eval(input())))

H = sorted(H,reverse = False)

C = Counter(H)

CH = list(C.values()) 



cnt = 0

for i in range(len(CH)):

    if CH[i] >= K:

        cnt += 1

        break

ans = 999999999999999

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

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



if cnt != 0:

    print('0')

else:

    print(ans)
from collections import Counter



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

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

H = sorted(H,reverse = False)



ans = 999999999999999

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

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

print(ans)
from collections import Counter

N, K = list(map(int, input().split()))
H = []
for i in range(N):
    H.append(int(eval(input())))
H = sorted(H, reverse=False)
C = Counter(H)
CH = list(C.values())
cnt = 0
for i in range(len(CH)):
    if CH[i] >= K:
        cnt += 1
        break
ans = 999999999999999
for i in range(N - K + 1):
    ans = min(ans, H[K - 1 + i] - H[i])
if cnt != 0:
    print("0")
else:
    print(ans)

from collections import Counter

N, K = list(map(int, input().split()))
H = [int(eval(input())) for _ in range(N)]
H = sorted(H, reverse=False)
ans = 999999999999999
for i in range(N - K + 1):
    ans = min(ans, H[K - 1 + i] - H[i])
print(ans)

-H = [] -for i in range(N): -    H.append(int(eval(input()))) +H = [int(eval(input())) for _ in range(N)] -C = Counter(H) -CH = list(C.values()) -cnt = 0 -for i in range(len(CH)): -    if CH[i] >= K: -        cnt += 1 -        break -if cnt != 0: -    print("0") -else: -    print(ans) +print(ans)