-----
HALLOWEEN EVE
-----

In some other world, today is Halloween Eve.There are N trees planted in Mr. Smith’s
garden. The height of the i-th tree (1≤i≤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 hmax meters, and the
height of the shortest decorated tree be hmin meters.
The smaller the value hmax−hmin is, the better. What is the minimum possible value of
hmax−hmin?

		
		

-----Constraints-----

	    2≤K< N ≤105 

1≤hi≤109

hi is an integer
	

-----Input Format-----

Input is given from Standard Input in the following format:

N K 

h1 

h2 

: 

hN

-----Output-----

Print the minimum possible value of hmax−hmin.

		
		

-----Example Text Case-----
Input:

5 3
10
15
11
14
12

Output:

2

Explanation

If we decorate the first, third and fifth trees, hmax=12,hmin=10 so hmax−hmin=2. This is
optimal.

Difficulty: UNKNOWN_DIFFICULTY

Starter code:

Solutions:
try:
	a = list(map(int, input().split()))
	n = a[0]
	k = a[1]
	hi = []
	for i in range(n):
		hi.append(int(input()))
	hi.sort()
	diff = []
	for i in range(n - k + 1):
		diff.append(hi[i + k - 1] - hi[i])
	print(min(diff))
except:
	pass


(N, K) = map(int, input().split())
l = []
i = 0
while i < N:
	i += 1
	l.append(int(input()))
l.sort()
m = 'n'
for i in range(N - K + 1):
	if m == 'n' or l[i + K - 1] - l[i] < m:
		m = l[i + K - 1] - l[i]
print(m)


(n, k) = list(map(int, input().split()))
arr = []
for _ in range(n):
	arr.append(int(input()))
arr.sort()
min = arr[n - 1]
for i in range(n - k):
	temp = arr[k + i - 1] - arr[i]
	if temp < min:
		min = temp
print(min)


(n, k) = map(int, input().split())
hs = sorted([int(input()) for _ in range(n)])
m = hs[k - 1] - hs[0]
i = k
while i < n:
	new = hs[i] - hs[i - k + 1]
	if new < m:
		m = new
	i += 1
print(m)


(n, k) = map(int, input().split())
l = []
l.append(-1)
for i in range(n):
	l.append(int(input()))
l.sort()
m = l[k] - l[1]
for i in range(2, n - k):
	if l[i + k - 1] - l[i] < m:
		m = l[i + k - 1] - l[i]
print(m)


(n, k) = list(map(int, input().split()))
a = []
for _ in range(n):
	a.append(int(input()))
a.sort()
hmin = a[0]
hmax = a[k - 1]
d = hmax - hmin
for i in range(0, len(a) - k):
	if d > a[k + i - 1] - a[i]:
		d = a[k + i - 1] - a[i]
print(d)


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


from sys import stdin, stdout
for _ in range(1):
	(n, k) = list(map(int, stdin.readline().split()))
	a = []
	ans = float('inf')
	for _ in range(n):
		a += [int(stdin.readline())]
	a.sort()
	for i in range(n - k + 1):
		ans = min(ans, abs(a[i] - a[i + k - 1]))
	print(ans)


(n, k) = list(map(int, input().split()))
l = []
l2 = []
for i in range(n):
	a = int(input())
	l.append(a)
l.sort()
for i in range(n - k + 1):
	l1 = []
	for j in range(i, k + i):
		l1.append(l[j])
	hmax = max(l1)
	hmin = min(l1)
	d = hmax - hmin
	l2.append(d)
print(min(l2))


(n, k) = [int(x) for x in input().split()]
a = []
res = []
for _ in range(n):
	a.append(int(input()))
a.sort()
for _ in range(n - k + 1):
	res.append(abs(a[_] - a[_ + k - 1]))
print(min(res))


x = input()
lst = x.split()
n = int(lst[0])
m = int(lst[1])
l = list()
for i in range(n):
	l.append(int(input()))
l.sort()
k = 0
mn = 100000000000000
while m + k <= n:
	s = l[m + k - 1] - l[k]
	if mn > s:
		mn = s
	k += 1
print(mn)


(n, k) = tuple(map(int, input().split()))
h = []
for i in range(n):
	h.append(int(input()))
h.sort()
dhmin = 10000000000.0
for i in range(n - k + 1):
	temp = h[i + k - 1] - h[i]
	dhmin = temp if temp < dhmin else dhmin
print(dhmin)


try:
	(n, k) = map(int, input().split())
	l = []
	for i in range(n):
		l.append(int(input()))
	l.sort()
	res = l[0 + k - 1] - l[0]
	for i in range(n - k + 1):
		d = l[i + k - 1] - l[i]
		res = min(res, d)
	print(res)
except EOFError as e:
	pass


(n, k) = list(map(int, input().split()))
heights = [0 for i in range(n)]
for height in range(n):
	heights[height] = int(input())
heights.sort()
decorated_trees = heights[:k]
height_differences = decorated_trees[-1] - decorated_trees[0]
for i in range(n - k + 1):
	decorated_trees = heights[i:i + k]
	height_differences = min(height_differences, decorated_trees[-1] - decorated_trees[0])
print(height_differences)


try:
	(n, k) = map(int, input().split())
	l = []
	for i in range(n):
		h = int(input())
		l.append(h)
	l.sort()
	mn = max(l)
	for i in range(n - k):
		mn = min(mn, l[i + k - 1] - l[i])
	print(mn)
except:
	pass


from sys import stdin, stdout
input = stdin.readline
from collections import defaultdict as dd
import math

def geti():
	return list(map(int, input().strip().split()))

def getl():
	return list(map(int, input().strip().split()))

def gets():
	return input()

def geta():
	return int(input())

def print_s(s):
	stdout.write(s + '\n')

def solve():
	(n, k) = geti()
	a = []
	for i in range(n):
		a.append(geta())
	a.sort()
	ans = float('inf')
	for i in range(n - k + 1):
		ans = min(ans, a[i + k - 1] - a[i])
	print(ans)

def __starting_point():
	solve()
__starting_point()


import sys
(n, k) = map(int, input().strip().split())
trees = []
for _ in range(n):
	trees.append(int(input().strip()))
trees.sort()
minimo = 1000
for i in range(0, n - k + 1):
	minimo = min(minimo, trees[i + k - 1] - trees[i])
print(minimo)


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


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


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


line1 = [int(x) for x in input().split()]
n = line1[0]
k = line1[1]
arr = []
while n > 0:
	arr.append(int(input()))
	n -= 1
arr.sort()
i = 0
j = k - 1
mini = 110
if j >= len(arr):
	print(arr[len(arr) - 1] - arr[0])
else:
	while j < len(arr):
		mini = min(arr[j] - arr[i], mini)
		i += 1
		j += 1
	print(mini)


(x, k) = map(int, input().split())
l = []
for i in range(x):
	l = l + [int(input())]
l.sort()
i = 0
min = 2 ** 64
while i + k < len(l):
	if l[i + k - 1] - l[i] < min:
		min = l[i + k - 1] - l[i]
	i += 1
print(min)


(n, k) = list(map(int, input().split()))
l = []
for _ in range(n):
	l.append(int(input()))
l.sort()
m = l[k - 1] - l[0]
for i in range(n - k):
	if l[k - 1 + i] - l[i] < m:
		m = l[i + k - 1] - l[i]
print(m)


(n, k) = list(map(int, input().split(' ')))
l = []
for i in range(n):
	a = int(input())
	l.append(a)
l.sort()
mini = 10 ** 10
for i in range(n - k + 1):
	mini = min(mini, l[i + k - 1] - l[i])
print(mini)


(n, k) = map(int, input().split())
trees = []
for i in range(n):
	trees.append(int(input()))
trees.sort()
minimum = 10 ** 5
for i in range(0, n - k + 1, 1):
	temp = trees[i + k - 1] - trees[i]
	minimum = min(temp, minimum)
print(minimum)