# import sys

# input = sys.stdin.readline



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

h = [0]*n



for i in range(n):

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



h.sort()



ans = 10**9

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

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

    if ans > temp:

        ans = temp

print(ans)
import sys

input = sys.stdin.readline



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



# h = [0]*n

# for i in range(n):

#     h[i] = int(input())



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



h.sort()



ans = 10**9

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

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

    ans = min(ans, temp)



print(ans)
# import sys
# input = sys.stdin.readline
n, k = list(map(int, input().split()))
h = [0] * n
for i in range(n):
    h[i] = int(eval(input()))
h.sort()
ans = 10**9
for i in range(n - k + 1):
    temp = h[i + k - 1] - h[i]
    if ans > temp:
        ans = temp
print(ans)

import sys

input = sys.stdin.readline
n, k = list(map(int, input().split()))
# h = [0]*n
# for i in range(n):
#     h[i] = int(input())
h = [int(eval(input())) for _ in range(n)]
h.sort()
ans = 10**9
for i in range(n - k + 1):
    temp = h[i + k - 1] - h[i]
    ans = min(ans, temp)
print(ans)

-# import sys -# input = sys.stdin.readline +import sys + +input = sys.stdin.readline -h = [0] * n -for i in range(n): -    h[i] = int(eval(input())) +# h = [0]*n +# for i in range(n): +#     h[i] = int(input()) +h = [int(eval(input())) for _ in range(n)] -    if ans > temp: -        ans = temp +    ans = min(ans, temp)