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

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

list1.sort()

treemin = 10**9

for i in range(len(list1)-k+1):

	treemin = min(treemin,list1[i+k-1]-list1[i])

print(treemin)
import sys

readline = sys.stdin.buffer.readline

def even(n): return 1 if n%2==0 else 0



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

lst1 = []

for i in range(n):

    lst1.append( int(readline()))

lst1.sort()

ans = 10**9

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

    ans = min(ans,abs(lst1[i+k-1]-lst1[i]))



print(ans)



n, k = list(map(int, input().split()))
list1 = [int(eval(input())) for i in range(n)]
list1.sort()
treemin = 10**9
for i in range(len(list1) - k + 1):
    treemin = min(treemin, list1[i + k - 1] - list1[i])
print(treemin)

import sys

readline = sys.stdin.buffer.readline


def even(n):
    return 1 if n % 2 == 0 else 0


n, k = list(map(int, readline().split()))
lst1 = []
for i in range(n):
    lst1.append(int(readline()))
lst1.sort()
ans = 10**9
for i in range(n - k + 1):
    ans = min(ans, abs(lst1[i + k - 1] - lst1[i]))
print(ans)

-n, k = list(map(int, input().split())) -list1 = [int(eval(input())) for i in range(n)] -list1.sort() -treemin = 10**9 -for i in range(len(list1) - k + 1): -    treemin = min(treemin, list1[i + k - 1] - list1[i]) -print(treemin) +import sys + +readline = sys.stdin.buffer.readline + + +def even(n): +    return 1 if n % 2 == 0 else 0 + + +n, k = list(map(int, readline().split())) +lst1 = [] +for i in range(n): +    lst1.append(int(readline())) +lst1.sort() +ans = 10**9 +for i in range(n - k + 1): +    ans = min(ans, abs(lst1[i + k - 1] - lst1[i])) +print(ans)