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



H = [0]*N

for i in range(N):

  H[i] = int(eval(input()))

H.sort()

m = H[-1]-H[0]

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

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

print(m)
def solve():

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

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

  H.sort()

  ans = float('inf')

  for i in range(N):

    if i+K>N:

      break

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

  return ans

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

def solve():
    N, K = list(map(int, input().split()))
    H = [int(eval(input())) for _ in range(N)]
    H.sort()
    ans = float("inf")
    for i in range(N):
        if i + K > N:
            break
        ans = min(H[i + K - 1] - H[i], ans)
    return ans


print((solve()))

-N, K = list(map(int, input().split())) -H = [0] * N -for i in range(N): -    H[i] = int(eval(input())) -H.sort() -m = H[-1] - H[0] -for i in range(N - K + 1): -    m = min(m, H[i + K - 1] - H[i]) -print(m) +def solve(): +    N, K = list(map(int, input().split())) +    H = [int(eval(input())) for _ in range(N)] +    H.sort() +    ans = float("inf") +    for i in range(N): +        if i + K > N: +            break +        ans = min(H[i + K - 1] - H[i], ans) +    return ans + + +print((solve()))