In some other world, today is Christmas Eve.
There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.
He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.
More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

-----Constraints-----
 - 2 \leq K < N \leq 10^5
 - 1 \leq h_i \leq 10^9
 - h_i is an integer.

-----Input-----
Input is given from Standard Input in the following format:
N K
h_1
h_2
:
h_N

-----Output-----
Print the minimum possible value of h_{max} - h_{min}.

-----Sample Input-----
5 3
10
15
11
14
12

-----Sample Output-----
2

If we decorate the first, third and fifth trees, h_{max} = 12, h_{min} = 10 so h_{max} - h_{min} = 2. This is optimal.

Difficulty: introductory

Starter code:

Solutions:
n,k = map(int,input().split())
L = sorted(list(int(input()) for _ in range(n)))
m = 10**9

for i in range(n-k+1):
  m = min(m, L[i+k-1]-L[i])

print(m)

N,K=map(int,input().split())
L=[]
for i in range(N):
    L.append(int(input().rstrip()))
L.sort()
M=[]
for i in range(N-K+1):
    M.append(L[K+i-1]-L[i])
M.sort()
print(M[0])

N,K = map(int,input().split())
high = [int(input()) for _ in range(N)]
s_high = sorted(high)
ans = 10**9
#print(s_high)
for i in range(N-K+1):
    j = s_high[i+K-1] - s_high[i]
    ans = min(ans,j)
print(ans)

n, k = map(int, input().split())
h = []
for i in range(n):
  h_ = int(input())
  h.append(h_)
h.sort()
#print(h)
ans = float('inf')
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()))
h = [int(input()) for i in range(n)]
h.sort()
ans = []
for i in range(n - k + 1):
    ans.append(h[i + k - 1] - h[i])
print((min(ans)))


n,k = map(int, input().split())
h = sorted([int(input()) for _ in range(n)])
ans = []

for i in range(n-k+1):
    ans.append(h[i+k-1]-h[i])
print(min(ans))

n,k=map(int, input().split())
h=[]
for i in range(n):
  h.append(int(input()))
h.sort()
ans=h[k-1]-h[0]
for i in range(1,n-k+1):
  ans=min(ans,h[i+k-1]-h[i])
print(ans)

n, k = list(map(int, input().split( )))
arr = []
for _ in range(n):
  arr.append(int(input()))
a = sorted(arr)
m = 10**9
for i in range(n-k+1):
  ma = a[i+k-1] - a[i]
  m = min(m, ma)
print(m)
  


n,k=map(int,input().split())
h=[int(input()) for _ in range(n)]

h.sort()
result = 10**9
for i in range(n-k+1):
  result = min(result, h[i+k-1] - h[i])

print(result)

N, K = map(int, input().split())
h = [0] * N
for i in range(N):
    h[i] = int(input())

h = sorted(h)
ans = 10**10
for i in range(N - K + 1):
    ans = min(ans, h[i + K - 1] - h[i])

print(ans)

n,k= map(int,input().split())
l = []
for i in range(n):
  l.append(int(input()))
b = sorted(l)
ans = b[k-1] - b[0]
for i in range(n-k+1):
  ans = min(ans,b[i+k-1] - b[i])
print(ans)

N, K = map(int, input().split())
T = sorted([int(input()) for _ in range(N)])

result = 10 ** 9
for i in range(N-K+1):
  result = min(result, T[i+K-1]-T[i])

print(result)

n,k = map(int,input().split())
h = [int(input()) for _ in range(n)]

h.sort()
#小さい順に並べられたk本の木の、一番低い奴と高い奴の高さの差
dh = [int(1e9)]*n
for i in range(k-1,n):
    dh[i]=h[i]-h[i-k+1]
    
print(min(dh))

# C

N,K = map(int,input().split())
H = sorted([int(input()) for _ in range(N)])
print(min(H[i+K-1]-H[i] for i in range(N-K+1)))

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K, *H = list(map(int, read().split()))

    H.sort()

    ans = INF
    for i in range(N - K + 1):
        if ans > H[i + K - 1] - H[i]:
            ans = H[i + K - 1] - H[i]
    print(ans)
    return


def __starting_point():
    main()

__starting_point()

n, k =list(map(int, input().split()))
hs = [int(input()) for _ in range(n)]
hs.sort()
#print(hs)
an = hs[k-1]-hs[0]
for i in range(1,n-k+1):
    ans = hs[i+k-1]-hs[i]
    an = min(an, ans)
    #print(an)
print(an)



# -*- coding: utf-8 -*-
"""
Created on Sun Sep 13 03:08:56 2020

@author: liang
"""

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


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

H = []
for i in range(N):
    H.append(int(input()))

H.sort()

ans = 1000000009

for i in range(N-K+1):
    ans = min(ans, H[i+K-1]-H[i])

print(ans)

n,k=map(int,input().split())
h=list(int(input()) for i in range(n))
h.sort()

c=[]

for i in range(n-k+1):
  a=h[i+k-1]-h[i]
  c.append(a)

print(min(c))

N, K = map(int,input().split())
H = []
min_dif = 1000000000000000000000000

for n in range(N):
  h = int(input())
  H.append(h)

H.sort()

for i in range(N-K+1):
  dif = H[i+K-1] - H[i]
  if dif < min_dif:
    min_dif = dif
    
print(min_dif)

n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
h = sorted(h)
H = []

for i in range(n-k+1):
    H_i = h[i+k-1]-h[i]
    H.append(H_i)

print(min(H))

n,k = map(int,input().split())
h = []

for i in range(n):
    h.append(int(input()))

h.sort()

ans = 1000000000

for j in range(n-k+1):
    s = h[j+k-1] - h[j]
    if s < ans:
        ans = s

print(ans)

n,k=map(int,input().split())
h=[int(input()) for _ in range(n)]
l=[]
h.sort()
for i in range(n+1-k):
  x=h[i+k-1]-h[i]
  l.append(x)
print(min(l))

#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def ngram(numbers,n):
    return list([numbers[i:i+n] for i in range(len(numbers)-2)])

def main():
    numbers=[]
    n,m = map(int,input().split())
    [numbers.append(int(input())) for _ in range(n)]
    numbers.sort()
    print(min(numbers[i+m-1] - numbers[i] for i in range(n-m+1)))

def __starting_point():
    main()
__starting_point()

N,K = map(int,input().split())
H = sorted([int(input()) for n in range(N)])
ans = H[-1]-H[0]

for n in range(N-K+1):
  ans = min(ans,H[n+K-1]-H[n])
  
print(ans)

n,k=map(int,input().split())
h=sorted([int(input()) for i in range(n)])
print(min([h[i+k-1]-h[i] for i in range(n-k+1)]))

N, K = map(int, input().split())
A = [int(input()) for _ in range(N)]
B = sorted(A)
ans = []
for i in range(N-K+1):
  ans.append(B[i+K-1]-B[i])
print(min(ans))

N,K = map(int,(input().split()))
h = [int(input())for _ in range(N)]
h.sort()

print(min(h[i+K-1]-h[i] for i in range(N-K+1)))

N,K = list(map(int,input().split()))
h = [int(input()) for i in range(N)]
h.sort(reverse = True)
minimum = 10**9
for i in range(N-K+1):
    minimum = min(minimum,h[i] - h[i+K-1])
print(minimum)


n, k = map(int, input().split())
ab = [int(input()) for _ in range(n)]

sab = sorted(ab)

res = 10**10

for i in range(n-k+1):
    res = min(res,sab[i+k-1]-sab[i])

print(res)

# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, K, h):
    h.sort()
    ans = 10 ** 9
    for i in range(K - 1, N):
        ans = min(ans, h[i] - h[i - (K - 1)])
    print(ans)


def __starting_point():
    N, K = list(map(int, input().split()))
    h = [int(input()) for _ in range(N)]
    solve(N, K, h)

    # # test
    # from random import randint
    # from func import random_str
    # N, K = 10 ** 5, 10 ** 5 // 5
    # h = [randint(1, 10 ** 9) for _ in range(N)]
    # solve(N, K, h)

__starting_point()

n,k = map(int, input().split())
h = [ int(input()) for _ in range(n)]
h.sort()

def check(x):
  for i in range(n):
    if i+k-1 >= n:
      continue
    if h[i+k-1] - h[i] <= x:
      return True
  return False
    
hmax, hmin = max(h), min(h)
fv, tv = -1, (hmax-hmin)
while tv - fv > 1:
  mid = (tv + fv) // 2
  if check(mid):
    tv = mid
  else:
    fv = mid
print(tv)

n,k = map(int, input().split())
h = sorted(list(int(input()) for _ in range(n)))
ans = []
for i in range(n-k+1):
    ans.append(h[i+k-1]-h[i])
print(min(ans))

n,k=map(int,input().split())
H=[]
for i in range(n):
    H.append(int(input()))
H.sort()
ans = min( H[i+k-1]-H[i] for i in range( n-k+1 ) )
print(ans)

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

trees = []
for _i in range(n):
  tree = int(input())
  trees.append(tree)

trees.sort()
ans = float('inf')

for i in range(n - k + 1):
  diff = trees[i + k - 1] - trees[i]
  if ans > diff:
    ans = diff

print(ans)

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

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

l.sort()
mi = float('INF')
for i in range(n-k+1):
    sub = l[i+k-1]-l[i]
    mi = min(mi,sub)

print(mi)

n,m = list(map(int,input().split(' ')))
a = []
for i in range(n):
    x = int(input())
    a.append(x)
a.sort()
mn = 1000000000
for i in range(m-1,n):
    mn = min(a[i] - a[i - m+1],mn)
print(mn)


n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
h.sort(reverse=True)
ans=float('inf')
for i in range(n-k+1):
  ans=min(h[i]-h[i+k-1],ans)
print(ans)

n,k = map(int,input().split())
h = [0]*n
for i in range(n):
  h[i]=int(input())
h = sorted(h)
answer = 100000000000000
for j in range(n+1-k):
  answer = min(answer,h[j-1+k]-h[j])
print(answer)

n, k = map(int, input().split())
hl = sorted(list(int(input()) for _ in range(n)))

ans = 1001001001
for i in range(n-k+1):
    ans = min(hl[i+k-1]-hl[i], ans)

print(ans)

from sys import stdin
from collections import defaultdict
input = stdin.readline
# ~ T = int(input())
T = 1
for t in range(1,T + 1):
	n,k = list(map(int,input().split()))
	_input = []
	for i in range(n):
		_input.append(int(input()))
	_input.sort()
	min_ans = 10000000000
	for i in range(k - 1,len(_input)):
		min_ans = min(min_ans,_input[i] - _input[i - k + 1])
	print(min_ans)


n,k=map(int,input().split())
h=[int(input()) for i in range(n)]

h.sort()

l=[]
for i in range(n-k+1):
        a=h[i+k-1]-h[i]
        l.append(a)

print(min(l))

n,k = map(int,input().split())
h = [int(input()) for _ in range(n)]
h.sort()
ans = [h[i+k-1]-h[i] for i in range(n-k+1)]
print(min(ans))

n,k=map(int,input().split())
h=sorted([int(input()) for i in range(n)])
c= float('inf')
for i in range(n-k+1):
    c=min(c,h[i+k-1]-h[i])
print(c)

N, K = list(map(int, input().split()))
h = []
ans = 1000000000

for i in range(N):
    h.append(int(input()))

h = sorted(h)

for j in range(N-K+1):
    if ans > h[j+K-1]-h[j]:
        ans = h[j+K-1]-h[j]
print(ans)


n,k =map(int,input().split())
h = [int(input()) for _ in range(n)]
l = []
h.sort()
for i in range(n+1-k):
        x = h[i+k-1] - h[i]
        l.append(x)
print(min(l))

n, k = map(int,input().split())
h = [int(input()) for _ in range(n)]
h = sorted(h)
hmin = 1e10
for i in range(n-k+1):
    hmin = min(hmin,h[i+k-1]-h[i])
print(hmin)

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

h = []
for i in range(N):
    h.append(int(input()))
    
h.sort()
h.reverse()

ls = []

for i in range(N - K + 1):
    ls.append(h[i] - h[i + K - 1])

print((min(ls)))


N, K = map(int, input().split())
H = [int(input()) for _ in range(N)]
H.sort(reverse=True)

min_h = float('inf')
for i in range(N-K+1):
    temp = H[i] - H[i+K-1]
    min_h = min(min_h, temp)


print(min_h)

n,k=map(int,input().split())
h=[]
ma=10**9
for i in range(n):
  a=int(input())
  h.append(a)
h.sort()

for i in range(n-k+1):
  sa=h[k-1+i]-h[i]
  if sa<ma:
    ma=sa
    
print(ma)

n,k=map(int,input().split())
h=sorted([int(input()) for i in range(n)])
print(min(h[i+k-1]-h[i] for i in range(n-k+1)))

N, K = map(int, input().split())
h = []
for i in range(N):
  h.append(int(input()))
h.sort()
ans = 1000000000
for i in range(N-K+1):
  ans = min(ans, h[i+K-1]-h[i])
print(ans)

n, k = map(int, input().split())
h = sorted([int(input()) for _ in range(n)], reverse=True)

m = float('inf')
for i in range(n-k+1):
  m = min(m, h[i]-h[i+k-1])

print(m)

n, k = map(int, input().split())
hl = []
for i in range(n):
    hl.append(int(input()))

hl.sort()
ans = 10000000001

for j in range(n-k+1):
    s = hl[j+k-1] - hl[j]
    if s < ans:
        ans = s
    else:
        pass
print(ans)

n,k = map(int, input().split())
h = sorted([int(input()) for _ in range(n)])

nums = [0]*(n-1)
for i in range(n-1): nums[i] = h[i+1]-h[i]

ans = sum(nums[:k-1])
t = sum(nums[:k-1])
for i in range(k-1,n-1):
  t += nums[i] - nums[i-k+1]
  if t < ans: ans = t
print(ans)

N, K = map(int, input().split())
L = []
mini = float('inf')

for i in range(N):
    h = int(input())
    L.append(h)

L.sort(reverse=True)

for i in range(len(L)-K+1):
    if L[i] - L[i+K-1] < mini:
        if L[i] - L[i+K-1] == 0:
            print(0)
            return
        else:
            mini = L[i] - L[i+K-1]

print(mini)

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

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

ans=H[K-1]-H[0]

for k in range(N-K+1):
	#print(H[k+K-1],H[k])
	ans=min(ans,H[k+K-1]-H[k])

print(ans)

N,K = map(int,input().split())
h = [0]*N
for i in range(N):
    h[i] = int(input())
h = sorted(h)
ans = 10**10
for i in range(N-(K-1)):
    tmp = h[i+K-1] - h[i]
    ans = min(tmp,ans)
print(ans)

n,k=map(int,input().split())
listh=[]
for i in range(n):
  listh.append(int(input()))
listh.sort()
ans=10**9
for i in range(n-k+1):
  high=listh[i+k-1]-listh[i]
  if high<ans:
    ans=high

print(ans)

N, K = map(int, input().split())
H = sorted([int(input()) for i in range(N)])
list1 = []

for i in range(N - K + 1):
 
  h = H[i + K -1]-H[i]
  list1.append(h)

print(min(list1)) 

#!/usr/bin/env python3
n,k=map(int,input().split())
h=[int(input()) for _ in range(n)]
h.sort()
ans=1000000007
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()))
a=[int(input()) for i in range(N)]

a.sort()
ans=100000000000000000000000

for j in range(N-K+1):
    if a[j+K-1]-a[j]<ans:
        ans=a[j+K-1]-a[j]


print(ans)


n, k = list(map(int, input().split()))
h = [int(input()) for i in range(n)]
h.sort()

ans = 100000000000000000000000000000000000000
for i in range(n-k+1):
    ans = min(ans, h[i+k-1] - h[i])
print(ans)


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

N,K=list(map(int,input().split()))
h=[0]*N
for H in range(N):
    h[H-1]=int(input())
A=sorted(h)
L=K-1
M=A[L]-A[0]
O=(N-K)+1
for j in range(O):
    if M>A[L+j]-A[j]:
        M=A[L+j]-A[j]
print(M)


N,K = map(int,input().split())
H = [int(input()) for _ in range(N)]

H.sort()
ans = float("inf")

for i in range(N-K+1):
  tmp = H[i+K-1] - H[i]
  ans = min(ans, tmp)
  
print(ans)

def main():
    n, k = map(int, input().split(" "))
    data = sorted(int(input()) for _ in range(n))
    print(min([data[i+k-1] - data[i] for i in range(n-k+1)]))
main()

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

N, K, *H = list(map(int, open(0).read().split()))
H.sort()
print((min(H[i + K - 1] - H[i] for i in range(N - K + 1))))


n, k = map(int , input().split())
hn = [int(input()) for _ in range(n)]
hn.sort()

print(min(hn[i+k-1]-hn[i] for i in range(n-k+1)))

n, k = map(int, input().split())
lis = []
ans = 1000000000000000000

for _ in range(n):
  lis.append(int(input()))

lis.sort()

for i in range(n):
  if i+k-1 >= len(lis):
    break
  else:
    mi = abs(lis[i] - lis[i+k-1])
    ans = min(ans, mi)

print(ans)

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

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

h.sort()

s = h[-1] - h[1]

for i in range(n-k+1):
    s = min(s, h[i+k-1]-h[i])

print(s)


N,K=list(map(int,input().split()))
h=[int(input()) for _ in range(N)]
h.sort()
print((min(h[i+K-1]-h[i] for i in range(N-K+1))))


import numpy as np

N, K = list(map(int, input().split()))
H = [int(input()) for _ in range(N)]

sH = np.array(sorted(H), dtype=np.int64)
shift = sH[K-1:]
diff = shift - sH[:len(shift)]
ans = min(diff)
print(ans)


# coding: utf-8


def main():
    N, K = list(map(int, input().split()))
    H = sorted([int(input()) for _ in range(N)])
    ans = min([H[i + K - 1] - H[i] for i in range(N - K + 1)])

    print(ans)

def __starting_point():
    main()

__starting_point()

import math
import collections
from itertools import product

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n, k = mi()
h = [ii() for i in range(n)]
h.sort()
ans = 10**12
for i in range(n):
    last = i + k - 1
    if last >= n:
        break
    ans = min(ans, h[last]-h[i])
print(ans)

N,K = map(int, input().split())
h = []
for i in range(N):
  tmp = int(input())
  h.append(tmp)
h.sort()

ans = h[N-1]
for i in range(0, N-K+1):
  tmp = h[i+K-1] - h[i]
  ans = min(ans, tmp)
print(ans)

#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
# from math import gcd
# from itertools import combinations,permutations,accumulate, product # (string,3) 3回
# #from collections import deque
# from collections import deque,defaultdict,Counter
# import decimal
# import re
# import math
# import bisect
# import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
n,k = readInts()
A = [I() for _ in range(n)]
A = sorted(A)
a = INF
for i in range(n-k+1):
    #print(A[i+k-1], A[i])
    a = min(a,abs(A[i+k-1] - A[i]))
print(a)


import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    N, K = MI()
    L = [I() for i in range(N)]
    L.sort()
    res = float('inf')
    
    for i in range(N-K+1):
        res = min(res, L[i+K-1] - L[i])
    
    print(res)
def __starting_point():
    main()
__starting_point()

N, K = map(int,input().split())
h = [int(input()) for i in range(N)]
s_h = sorted(h)
tmp = []
ans1 = 0
ans2 = 0
ans3 = 0
for i in range(N-K+1):
    ans1 = s_h[i+K-1]
    ans2 = s_h[i]
    ans3 = ans1 - ans2
    tmp.append(ans3)

print(min(tmp))

N, K = map(int, input().split())
H = [int(input()) for _ in range(N)]

H.sort()

res = 10**9
for i in range(N - K + 1):
    res = min(res, H[i + K - 1] - H[i])

print(res)

n, k = map(int,input().split())
h_l = sorted([ int(input()) for _ in range(n)  ])
ans = float('inf')
for i in range(n-k+1):
    ans = min(h_l[i+k-1]-h_l[i],ans)
print(ans)

#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
import numpy as np

def main():
    numbers=[]
    n,m = map(int,input().split())
    [numbers.append(int(input())) for _ in range(n)]
    n_numbers=np.array(numbers,dtype=int)
    n_numbers.sort()
    print(min(n_numbers[i+m-1] - n_numbers[i] for i in range(n-m+1)))

def __starting_point():
    main()
__starting_point()

n,k = map(int,input().split())
s = []
for i in range(n):
    s.append(int(input()))
s.sort()
s.reverse()
ans = s[0]-s[-1]
for i in range(n-k+1):
    ans = min(ans,s[i]-s[i+k-1])
print(ans)

n,k = map(int,input().split())
h = sorted([int(input()) for _ in range(n)])

ans = float("inf")
for i in range(n-k+1):
    sa = h[i+k-1] - h[i]
    if ans > sa:
        ans = sa
        
print(ans)

import sys
input = sys.stdin.readline

n,k = map(int, input().split())
h_list = []

for _ in range(n):
    h_list.append(int(input()))

sort_h_list = sorted(h_list)

L_index = 0
R_index = 0
L_value = sort_h_list[0]
R_value = sort_h_list[0]
count = 0
ans = 10**9

#尺取り法ぽいの
while (R_index < n):
    if (count < k):
        count += 1
        R_value = sort_h_list[R_index]
        if count == k:
            ans = min(ans,R_value - L_value)
        R_index += 1

    else:
        count -= 1
        L_index += 1
        L_value = sort_h_list[L_index]

print(ans)

n,k = list(map(int,input().split()))
h = [int(input()) for _ in range(n)]
h.sort()
d = []
for i in range(n-k+1):
    d.append(abs(h[i] - h[i+k-1]))
print((min(d)))


def main():
    N, K = list(map(int, input().split()))
    h = []
    for _ in range(N):
        h.append(int(input()))
    h.sort()
    ans = pow(10, 10)
    for k in range(N-K+1):
        ans = min(ans, abs(h[k]-h[K-1+k]))
    print(ans)

def __starting_point():
    main()

__starting_point()

N, K, *H = map(int, open(0).read().split())
H.sort()
ans = float('inf')
for i in range(N - K + 1):
    ans =min(ans, H[i + K - 1] - H[i])
print(ans)


N, K = map(int, input().split())
h = [int(input()) for i in range(N)]
h.sort()
l = [h[i+K-1] - h[i] for i in range(N-K+1)]
print(min(l))

import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return list(map(int, input().split()))
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n, k = i_map()
    h = [i_input() for i in range(n)]
    h.sort()
    print((min(h[i+k-1] - h[i] for i in range(n-k+1))))


def __starting_point():
    main()

__starting_point()

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

for i in range(n):
    x = int(input())
    h.append(x)

h = sorted(h)
ans = 10**9
tmp = 0

for i in range(k-1, n):
    tmp = h[i] - h[i-(k-1)]
    if tmp < ans:
        ans = tmp

print(ans)


n,k=list(map(int,input().split()))
h=[int(input()) for _ in range(n)]
l=[]
h.sort()
for i in range(n+1-k):
  x=h[i+k-1]-h[i]
  l.append(x)
print((min(l)))


N,K = map(int,input().split())
h = []
for i in range(N):
  h.append(int(input()))
h.sort()
ans = 10 ** 18
for i in range(N-K+1):
  if h[i+K-1] - h[i] < ans:
    ans = h[i+K-1] - h[i]
print(ans)

N, K = map(int, input().split())
A = [int(input()) for _ in range(N)]
B = sorted(A)
ans = []
flag = 0
for i in range(N-K+1):
  ans.append(B[i+K-1]-B[i])
  flag = 1
print(min(ans) if flag == 1 else "0")

#C - Christmas Eve
N,K = map(int,input().split())
h = [int(input()) for _  in range(N)]
h = sorted(h, reverse = True)

diff = 10**9
for i in range(N-K+1):
    a = h[i]-h[i+K-1]
    if diff > a:
        diff = a
    if diff == 0:
        break
print(diff)

n, k = list(map(int, input().split()))
hs = [int(input()) for i in range(n)]

hs = sorted(hs)

diff = 10**12
for i in range(n-k+1):
    diff = min(diff, hs[i+k-1] - hs[i])

print(diff)


n, k = list(map(int, input().split()))
hl = sorted(list(int(input()) for _ in range(n)), reverse=True)
ans = 1001001001
for i in range(n-k+1):
    ans = min(ans, hl[i]-hl[i+k-1])
print(ans)


N,K = map(int,input().split())
H = []
sa = []

for i in range(N):
  H.append(int(input()))

H.sort()

for j in range(N-K+1):
  sa.append(H[K+j-1]-H[j])

print(min(sa))