# ABC115 C - Christmas Eve

import numpy as np

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

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



ans = 10**10

H.sort()



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

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

    ans = min(ans,t)

print(ans)
n,k=list(map(int,input().split()))

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

h.sort()

ans=10**12

for i in range(n-k+1):

    min_h=h[i+k-1]-h[i]

    ans=min(ans,min_h)

print(ans)







# ABC115 C - Christmas Eve
import numpy as np

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

n, k = list(map(int, input().split()))
h = [int(eval(input())) for i in range(n)]
h.sort()
ans = 10**12
for i in range(n - k + 1):
    min_h = h[i + k - 1] - h[i]
    ans = min(ans, min_h)
print(ans)

-# ABC115 C - Christmas Eve -import numpy as np - -N, K = list(map(int, input().split())) -H = [int(eval(input())) for _ in range(N)] -ans = 10**10 -H.sort() -for i in range(N - K + 1): -    t = H[i + K - 1] - H[i] -    ans = min(ans, t) +n, k = list(map(int, input().split())) +h = [int(eval(input())) for i in range(n)] +h.sort() +ans = 10**12 +for i in range(n - k + 1): +    min_h = h[i + k - 1] - h[i] +    ans = min(ans, min_h)