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

List = []

for i in range(N):

    List.append(int(eval(input())))

    

List.sort()

ans_list = []

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

    ans_list.append(List[i+K-1]-List[i])



ans_list.sort()

print((ans_list[0]))
N,K = list(map(int, input().split()))

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



ans = 10**12

H.sort()

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()))
List = []
for i in range(N):
    List.append(int(eval(input())))
List.sort()
ans_list = []
for i in range(N - K + 1):
    ans_list.append(List[i + K - 1] - List[i])
ans_list.sort()
print((ans_list[0]))

N, K = list(map(int, input().split()))
H = [int(eval(input())) for _ in range(N)]
ans = 10**12
H.sort()
for i in range(N - K + 1):
    ans = min(ans, H[i + K - 1] - H[i])
print(ans)

-List = [] -for i in range(N): -    List.append(int(eval(input()))) -List.sort() -ans_list = [] +H = [int(eval(input())) for _ in range(N)] +ans = 10**12 +H.sort() -    ans_list.append(List[i + K - 1] - List[i]) -ans_list.sort() -print((ans_list[0])) +    ans = min(ans, H[i + K - 1] - H[i]) +print(ans)