The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her n students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces).

The shop assistant told the teacher that there are m puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of f_1 pieces, the second one consists of f_2 pieces and so on.

Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let A be the number of pieces in the largest puzzle that the teacher buys and B be the number of pieces in the smallest such puzzle. She wants to choose such n puzzles that A - B is minimum possible. Help the teacher and find the least possible value of A - B.


-----Input-----

The first line contains space-separated integers n and m (2 ≤ n ≤ m ≤ 50). The second line contains m space-separated integers f_1, f_2, ..., f_{m} (4 ≤ f_{i} ≤ 1000) — the quantities of pieces in the puzzles sold in the shop.


-----Output-----

Print a single integer — the least possible difference the teacher can obtain.


-----Examples-----
Input
4 6
10 12 10 7 5 22

Output
5



-----Note-----

Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5.

Difficulty: EASY

Solutions:
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
d = []
for x in range(0, m - n + 1):
	d.append(a[x + n - 1] - a[x])
print(min(d))


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
least = a[n - 1] - a[0]
for i in range(1, m - n + 1):
	if a[i + n - 1] - a[i] < least:
		least = a[i + n - 1] - a[i]
print(least)


(n, m) = map(int, input().split())
v = sorted(list(map(int, input().split())))
print(min((v[i + n - 1] - v[i] for i in range(0, len(v) - n + 1))))


(n, m) = map(int, input().split())
lst = list(map(int, input().split()))
lst.sort()
d = lst[m - 1] - lst[0]
for i in range(m - n + 1):
	d = min(lst[i + n - 1] - lst[i], d)
print(d)


(n, m) = map(int, input().split())
s = input()
s = s.split()
l1 = []
for i in range(m):
	if s[i].isdigit():
		l1.append(int(s[i]))
l1.sort()
l4 = []
for i in range(len(l1)):
	l4.append(l1[i:i + n])
l3 = []
for i in l4:
	if len(i) == n:
		l3.append(max(i) - min(i))
print(min(l3))


(n, m) = map(int, input().split())
data = list(map(int, input().split()))
data = sorted(data)
print(min(list((j - i for (i, j) in zip(data, data[n - 1:])))))


(n, m) = map(int, input().split())
arr = [int(n) for n in input().split()]
list.sort(arr)
best = 1000000
for i in range(0, m - n + 1):
	best = min(arr[i + n - 1] - arr[i], best)
print(best)


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


import sys
(n, m) = [int(x) for x in input().split()]
ls = sorted([int(x) for x in input().split()])
minimum = sys.maxsize
for i in range(m - n + 1):
	new = ls[i + n - 1] - ls[i]
	if new < minimum:
		minimum = new
print(minimum)


def go():
	(n, m) = (int(i) for i in input().split(' '))
	f = list(sorted((int(i) for i in input().split(' '))))
	x = float('inf')
	for i in range(m - n + 1):
		x = min(x, f[i + n - 1] - f[i])
	return x
print(go())


(n, m) = [int(x) for x in input().split()]
pieces = [int(x) for x in input().split()]
min_pieces = 99999999
pieces.sort()
if n == m:
	min_pieces = pieces[-1] - pieces[0]
	print(min_pieces)
else:
	for _ in range(m - n + 1):
		difference = pieces[n - 1] - pieces[0]
		if difference < min_pieces:
			min_pieces = difference
		pieces.pop(0)
	print(min_pieces)


(n, m) = [int(x) for x in input().split()]
f = [int(x) for x in input().split()]
answer = 2 ** 10
f.sort()
[5, 7, 10, 10, 12, 22]
for i in range(m - n + 1):
	answer = min(answer, f[i + n - 1] - f[i])
print(answer)


import sys
inp1 = input()
inp2 = input()
inp1 = [int(x) for x in inp1.split()]
input_list = [int(x) for x in inp2.split()]
input_list.sort()
i = inp1[0] - 1
j = 0
least = sys.maxsize
while i < len(input_list):
	least = min(least, input_list[i] - input_list[j])
	i += 1
	j += 1
print(least)


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


(n, m) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
hasil = []
for i in range(len(a)):
	for j in range(i + 1, len(a)):
		if a[i] >= a[j]:
			(a[i], a[j]) = (a[j], a[i])
j = n - 1
for i in range(len(a)):
	if j == len(a):
		break
	else:
		t = a[j] - a[i]
		hasil += [t]
		j += 1
print(min(hasil))


(n, m) = [int(x) for x in input().split()]
f = [int(x) for x in input().split()]
f.sort()
different = f[-1] - f[0]
for i in range(m - n + 1):
	if f[n - 1 + i] - f[i] < different:
		different = f[n - 1 + i] - f[i]
print(different)


(n, m) = list(map(int, input().split()))
array = sorted(list(map(int, input().split())))
min_ = 10000000000
for k in range(0, m - n + 1):
	min_ = min(min_, array[k + n - 1] - array[k])
print(min_)


(n, m) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
r = a[-1]
for i in range(m - n + 1):
	t = a[i + n - 1] - a[i]
	if t < r:
		r = t
print(r)


def _337A(numbers, n):
	sorted_numbers = sorted(numbers)
	return min(list(map(lambda x: x[1] - x[0], list(zip(sorted_numbers, sorted_numbers[n - 1:])))))
(n, m) = list(map(lambda x: int(x), input().split()))
numbers = list(map(lambda x: int(x), input().split()))
print(_337A(numbers, n))


l = list(map(int, input().split(' ')))
(n, m) = (l[0], l[1])
lt = list(map(int, input().split(' ')))
lt.sort()
lt1 = lt[:n]
tmin = max(lt1) - min(lt1)
for i in range(0, len(lt) - n + 1):
	ln = lt[i:i + n]
	vmx = max(ln)
	vmn = min(ln)
	if vmx - vmn <= tmin:
		tmin = vmx - vmn
print(tmin)


(a, b) = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
mini = c[a - 1] - c[0]
for i in range(len(c) - a + 1):
	mini = min(mini, c[i + a - 1] - c[i])
print(mini)


(n, m) = map(int, input().split())
ar = list(map(int, input().split()))
ar.sort()
ar1 = []
for i in range(0, m - (n - 1)):
	count = 0
	b = ar[i:i + n]
	c = max(b) - min(b)
	ar1.append(c)
ar1.sort()
print(ar1[0])


(n, m) = list(map(int, input().split()))[:]
ilist = list(map(int, input().split()))
sortd = sorted(ilist)
diff = sortd[n - 1] - sortd[0]
for i in range(1, m - n + 1):
	if sortd[n - 1 + i] - sortd[i] < diff:
		diff = sortd[n - 1 + i] - sortd[i]
print(diff)


(m, n) = map(int, input().split())
l = list(map(int, input().split()))
l = sorted(l)
d = 1000
for i in range(n - m + 1):
	d = min(d, l[i + m - 1] - l[i])
print(d)


a = input().split()
a[0] = int(a[0])
a[1] = int(a[1])
b = input().split()
for i in range(a[1]):
	b[i] = int(b[i])
b = sorted(b)
c = []
for i in range(a[1] - a[0] + 1):
	c.append(b[i + a[0] - 1] - b[i])
print(min(c))


import random

def average(x):
	return sum(x) / len(x)

def shuffled(a):
	a = list(a)
	random.shuffle(a)
	return a

def read_ints():
	return [int(i) for i in input().split()]

def decrease(a):
	return [i - 1 for i in a]

def main():
	(n, m) = read_ints()
	a = read_ints()
	a.sort()
	b = [a[i + n - 1] - a[i] for i in range(m - n + 1)]
	print(min(b))
main()


(a, b) = map(int, input().split())
c = sorted(list(map(int, input().split())))
p = []
i = 0
while i + a - 1 <= b - 1:
	p.append(c[i + a - 1] - c[i])
	i += 1
print(min(p))


x = [int(b) for b in input().split()]
y = [int(b) for b in input().split()]
y = sorted(y)
q = []
for i in range(x[1] - x[0] + 1):
	q += [y[x[0] - 1 + i] - y[i]]
print(min(q))


(n, m) = map(int, input().split(' '))
L = [int(x) for x in input().split()]
L.sort()
ans = L[-1] - L[0]
for i in range(m - n + 1):
	ans = min(ans, L[i + n - 1] - L[i])
print(ans)


line = input()
(n, m) = [int(i) for i in line.split()]
line2 = input()
nums = [int(i) for i in line2.split()]
nums.sort()
ans = 1000000000000.0
k = n - 1
i = 0
while k < m:
	if nums[k] - nums[i] < ans:
		ans = nums[k] - nums[i]
	k += 1
	i += 1
print(ans)


(a, b) = map(int, input().split())
a = a - 1
line = list(map(int, input().split()))
line.sort()
let = []
for i in range(b - a):
	x = line[i + a] - line[i]
	let.append(x)
print(min(let))


(n, m) = [int(s) for s in input().split()]
f = sorted([int(s) for s in input().split()])
mm = f[-1] - f[0]
for i in range(m - n + 1):
	mm = min(f[i + n - 1] - f[i], mm)
print(mm)


(n, m) = [int(x) for x in input().split()]
lst = [int(x) for x in input().split()]
lst.sort()
temp = lst[n - 1] - lst[0]
for i in range(m - n + 1):
	if temp > lst[i + n - 1] - lst[i]:
		temp = lst[i + n - 1] - lst[i]
print(temp)


(a, b) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
maxi = 10000
for i in range(b - a + 1):
	d = l[i + a - 1] - l[i]
	if d < maxi:
		maxi = d
print(maxi)


(m, n) = input().split(' ')
m = int(m)
n = int(n)
a = input().split(' ')
min = 10000
max = 0
c = []
for i in range(n):
	a[i] = int(a[i])
a = sorted(a)
for i in range(n - m + 1):
	min = a[i]
	max = a[m + i - 1]
	c.append(max - min)
min1 = c[0]
for i in range(1, len(c)):
	if c[i] < min1:
		min1 = c[i]
print(min1)


(k, n) = map(int, input().split())
L = list(map(int, input().split()))
L.sort()
Ans = 1000
for i in range(n):
	if i + k > n:
		break
	if Ans > L[i + k - 1] - L[i]:
		Ans = L[i + k - 1] - L[i]
print(Ans)


(m, n) = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
arr.sort()
s = 2000
for i in range(n - m + 1):
	s = min(s, arr[i + m - 1] - arr[i])
print(s)


(a, b) = map(int, input().split())
c = [int(x) for x in input().split()]
c.sort()
e = 0
f = 0
g = a - 1
d = c[a - 1] - c[e]
for i in range(b - a + 1):
	f = c[g] - c[e]
	if f < d:
		d = f
	g += 1
	e += 1
print(d)


def main():
	(n, m) = [int(item) for item in input().split()]
	nums = [int(item) for item in input().split()]
	mindiff = -1
	nums.sort()
	for i in range(0, m - n + 1):
		diff = nums[i + n - 1] - nums[i]
		if diff < mindiff or mindiff == -1:
			mindiff = diff
	print(mindiff)
main()


(n, m) = [int(x) for x in input().split()]
f = [int(x) for x in input().split()]
f.sort()
best = float('inf')
for k in range(0, m - n + 1):
	best = min(best, f[k + n - 1] - f[k])
print(best)


def leastDifference():
	arr.sort()
	leastDiff = 100000
	for i in range(n, m + 1):
		leastDiff = min(leastDiff, abs(arr[i - 1] - arr[i - n]))
	return leastDiff
[n, m] = list(map(int, input().split()))
arr = [int(n) for n in input().split()]
print(leastDifference())


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


(nstudent, mpuzzel) = [int(x) for x in input().split()]
pieces = list(map(int, input().split(' ')))[:mpuzzel]
pieces.sort()
finaldiff = pieces[nstudent - 1] - pieces[0]
for i in range(1, len(pieces) - nstudent + 1):
	finaldiff = min(finaldiff, pieces[i + nstudent - 1] - pieces[i])
print(finaldiff)


(n, m) = map(int, input().split())
a = list(sorted(map(int, input().split())))
ans = 100500
for i in range(m - n + 1):
	ans = min(ans, a[i + n - 1] - a[i])
print(ans)


(a, b) = map(int, input().split())
d = [int(x) for x in input().split()]
d.sort()
min1 = d[b - 1] - d[0]
if min1 == 0:
	print(min1)
else:
	for i in range(0, b - a + 1):
		min2 = d[i + a - 1] - d[i]
		if min2 < min1:
			min1 = min2
	print(min1)


(x, y) = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
l.sort()
o = []
for i in range(y - x + 1):
	a = min(l[i:i + x])
	b = max(l[i:i + x])
	o.append(b - a)
print(min(o))


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


(n, m) = list(map(int, input().split()))
arr = list(map(int, input().split()))
if n == m:
	print(max(arr) - min(arr))
else:
	arr.sort()
	min1 = arr[m - 1]
	for i in range(m - n + 1):
		diff = arr[i + n - 1] - arr[i]
		if min1 > diff:
			min1 = diff
	print(min1)


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


(n, m) = map(int, input().split(' '))
f = sorted(list(map(int, input().split(' '))))
diff = 10000000
for i in range(m - n + 1):
	tmp = max(f[i:i + n]) - min(f[i:i + n])
	if diff > tmp:
		diff = tmp
print(diff)


b = list(map(int, input().rstrip().split()))
a = list(map(int, input().rstrip().split()))
n = b[1]
req = b[0]
a = sorted(a)
i = 0
c = []
while i <= n - req:
	c.append(abs(a[i] - a[i + req - 1]))
	i = i + 1
print(min(c))


numbers = list(map(int, input().split()))
n = numbers[0]
m = numbers[1]
numbers = list(map(int, input().split()))
numbers.sort()
min = 0
i = 0
while i < m - n + 1:
	f = 0
	if i == 0:
		f = 1
	x = numbers[i + n - 1] - numbers[i]
	if f == 1:
		min = x
	elif x < min:
		min = x
	i += 1
print(min)


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
f.sort()
s = []
for i in range(len(f) - n + 1):
	s.append(f[i + n - 1] - f[i])
s.sort()
print(s[0])


nm = input()
(n, m) = [int(i) for i in nm.split()]
puzzlestr = input()
puzzles = [int(i) for i in puzzlestr.split()]
puzzles.sort()
i = 0
min_diff = 99999999
while i + n <= len(puzzles):
	diff = puzzles[i + n - 1] - puzzles[i]
	if diff < min_diff:
		min_diff = diff
	i += 1
print(min_diff)


(n, k) = map(int, input().split())
a = sorted(list(map(int, input().split())))
diff = 2437894567
for i in range(k):
	j = i + n - 1
	if j >= k:
		break
	temp = a[j] - a[i]
	diff = min(diff, temp)
print(diff)


import sys
from random import choice, randint
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def MI():
	return map(int, sys.stdin.readline().strip().split())

def LI():
	return list(map(int, sys.stdin.readline().strip().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().strip().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().strip().split()]

def LS():
	return sys.stdin.readline().strip().split()

def I():
	return int(sys.stdin.readline().strip())

def F():
	return float(sys.stdin.readline().strip())

def S():
	return sys.stdin.readline().strip()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))
inp = sys.stdin.readline
out = sys.stdout.write

def main():
	(n, m) = MI()
	f = LI()
	f.sort()
	mn = 10000000
	for i in range(m - n):
		d = f[i + n - 1] - f[i]
		if d < mn:
			mn = d
	if f[-1] - f[m - n] < mn:
		mn = f[-1] - f[m - n]
	if mn != 10000000:
		pf(mn)
	else:
		pf(f[n - 1] - f[0])
main()


nm = input().split()
n = int(nm[0])
m = int(nm[1])
listt = input().split()
listt = [int(x) for x in listt]
listt = sorted(listt)
shorted_distance = 99999
for i in range(n - 1, len(listt)):
	distance = listt[i] - listt[i - (n - 1)]
	shorted_distance = min(distance, shorted_distance)
print(shorted_distance)


(a, b) = map(int, input().split())
c = list(map(int, input().strip().split()))
c.sort()
small = 1001
for i in range(b - a + 1):
	if c[i + a - 1] - c[i] < small:
		small = c[i + a - 1] - c[i]
print(small)


(n, m) = map(int, input().split())
ls = list(map(int, input().split()))
ls.sort()
for i in range(m - n + 1):
	if i == 0:
		m = ls[i + n - 1] - ls[i]
	elif m > ls[i + n - 1] - ls[i]:
		m = ls[i + n - 1] - ls[i]
print(m)


(n, m) = (int(i) for i in input().split())
f = [int(i) for i in input().split()]
f.sort()
best = f[-1] - f[0]
for i in range(m - n + 1):
	best = min(best, f[i + n - 1] - f[i])
print(best)


(n, m) = map(int, input().split())
f = sorted(map(int, input().split()))
print(min(map(lambda x: x[0] - x[1], zip(f[n - 1:], f[:-n + 1]))))


l = list(map(int, input().strip().split(' ')))
m = list(map(int, input().strip().split(' ')))
m.sort()
k = 99999999999999999999999999999999999999995
for i in range(len(m) - l[0] + 1):
	if abs(m[i + l[0] - 1] - m[i]) < k:
		k = m[i + l[0] - 1] - m[i]
if l[0] <= l[1]:
	print(k)
else:
	print(0)


a = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
l.sort()
b = 0
min = l[a[0] - 1] - l[0]
for i in range(len(l) - a[0] + 1):
	b = l[i + a[0] - 1] - l[i]
	if b <= min:
		min = b
print(min)


(n, m) = map(int, input().split())
jigs = list((int(x) for x in input().split()))
jigs.sort()
list = []
for i in range(len(jigs) - n + 1):
	saws = jigs[i:i + n]
	dif = saws[n - 1] - saws[0]
	list.append(dif)
print(min(list))


e = input().split()
n = int(e[0])
m = int(e[1])
l = []
a = input().split()
for i in a:
	l.append(int(i))
l.sort()
x = 1000
for i in range(m - n + 1):
	x = min(x, l[i + n - 1] - l[i])
print(x)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
x = 10 ** 5
i = n - 1
j = 0
while i < m:
	x = min(x, a[i] - a[j])
	i += 1
	j += 1
print(x)


line = input()
pui = line.split()
n = int(pui[0])
m = int(pui[1])
line = input()
ar = line.split()
ar = [int(i) for i in ar]
ar = sorted(ar)
i = m - 1
mi = None
while i + 1 >= n:
	j = 0
	while i - j + 1 >= n:
		dif = ar[i] - ar[j]
		if mi is None or dif < mi:
			mi = dif
		j = j + 1
	i = i - 1
print(mi)


(n, m) = [int(x) for x in input().split()]
pieces = [int(x) for x in input().split()]
numm = []
pieces.sort()
for i in range(m - n + 1):
	a = pieces[i + n - 1] - pieces[i]
	numm.append(a)
b = min(numm)
print(b)


import sys
it = iter(sys.stdin.read().splitlines())
(n, m) = [int(x) for x in next(it).split()]
s = [int(x) for x in next(it).split()]
s.sort()
res = s[-1]
t = m - n
for i in range(t + 1):
	dif = s[i - 1 + n] - s[i]
	if dif < res:
		res = dif
print(res)


(n, m) = map(int, input().split())
v = [int(i) for i in input().split()]
ans = 10 ** 9
for i in range(0, m):
	for j in range(0, m):
		if i == j or v[i] > v[j]:
			continue
		r = 0
		for x in v:
			if v[i] <= x <= v[j]:
				r += 1
		if r >= n:
			ans = min(ans, v[j] - v[i])
print(ans)


import math

def main():
	(n, m) = [int(i) for i in input().split(' ')]
	puzzles = [int(i) for i in input().split(' ')]
	puzzles.sort()
	dif = puzzles[m - 1] - puzzles[0]
	if n == m:
		return dif
	for i in range(0, m - n + 1):
		if dif > puzzles[i + n - 1] - puzzles[i]:
			dif = puzzles[i + n - 1] - puzzles[i]
	return dif
print(main())


(n, m) = input().split()
n = int(n)
m = int(m)
v = sorted([int(e) for e in input().split()])
d = [v[i + n - 1] - v[i] for i in range(len(v) - n + 1)]
print(min(d))


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


(a, b) = map(int, input().split())
c = [int(i) for i in input().split()]
c.sort()
d = max(c[:a]) - min(c[:a])
for i in range(1, b - a + 1):
	d = min(max(c[i:a + i]) - min(c[i:a + i]), d)
print(d)


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


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
arr = sorted(arr)
(i, ans) = (0, 10 ** 5)
while i + n <= m:
	ans = min(ans, arr[i + n - 1] - arr[i])
	i += 1
print(ans)


def Check(List, N):
	for i in set(l):
		if l.count(i) == N:
			return True
	else:
		return False
(N, M) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
R = []
if Check(l, N):
	print(0)
else:
	try:
		for i in range(0, len(l)):
			R.append(abs(l[i] - l[i + (N - 1)]))
	except:
		print(min(R))


(N, M) = map(int, input().split())
V = sorted(list(map(int, input().split())))
ans = 2899220461
for i in range(M - N + 1):
	ans = min(ans, V[i + N - 1] - V[i])
print(ans)


def ii():
	return int(input())

def mi():
	return map(int, input().split())

def si():
	return [int(x) for x in input().split()]

def ss():
	return [x for x in input()]
(a, b) = mi()
s = si()
s.sort()
ans = min(range(0, b - a + 1), key=lambda x: s[x + a - 1] - s[x])
print(s[ans + a - 1] - s[ans])


(n, m) = input().split()
n = int(n)
m = int(m)
x = [int(x) for x in input().split()]
if n != m:
	x.sort()
	y = []
	z = []
	for i in range(len(x) - 1):
		y.append(x[i + 1] - x[i])
	for i in range(len(y) - n + 2):
		z.append(sum(y[i:i + n - 1]))
	print(min(z))
else:
	print(max(x) - min(x))


import sys
(n, m) = map(int, sys.stdin.readline().split())
f = list(map(int, sys.stdin.readline().split()))
f.sort()
result = sys.maxsize
for i in range(0, m - n + 1):
	result = min(result, f[i + n - 1] - f[i])
print(result)


(n, m) = map(int, input().split())
a = sorted(map(int, input().split()))
print(min((j - i for (i, j) in zip(a, a[n - 1:]))))


(n, m) = map(int, input().split())
pz = list(map(int, input().split()))
pz.sort()
min_d = pz[-1] - pz[0]
for i in range(m - n + 1):
	d = pz[i + n - 1] - pz[i]
	if d < min_d:
		min_d = d
print(min_d)


def main():
	(n, m) = map(int, input().split())
	prob = sorted([int(number) for number in input().split()])
	min = None
	for i in range(m - n + 1):
		if min is None or prob[i + n - 1] - prob[i] < min:
			min = prob[i + n - 1] - prob[i]
	print(min)
main()


(n, m) = map(int, input().split())
s = sorted(map(int, input().split()))
possiblediff = []
for i in range(m - n + 1):
	possiblediff.append(s[i + n - 1] - s[i])
print(min(possiblediff))


(n, m) = map(int, input().split())
f = [int(num) for num in input().split()]
f.sort()
ans = 10000
for i in range(m - n + 1):
	ans = min(ans, f[i + n - 1] - f[i])
print(ans)


nums = [int(i) for i in input().split()]
pieces = [int(i) for i in input().split()]
pieces.sort()
mini = pieces[nums[0] - 1] - pieces[0]
for i in range(nums[1] - nums[0] + 1):
	dif = pieces[i + nums[0] - 1] - pieces[i]
	if dif < mini:
		mini = dif
print(mini)


(m, n) = map(int, input().split())
a = list(map(int, input().split()))
i = 0
min = 1000
a.sort()
while True:
	if n - i < m:
		break
	elif a[i + m - 1] - a[i] < min:
		min = a[i + m - 1] - a[i]
	i += 1
print(min)


(students, total) = list(map(int, input().split(' ')))
puzzles = list(map(int, input().split(' ')))
puzzles.sort()
minimum = 1001
for i in range(total - students + 1):
	minimum = min(minimum, puzzles[i + students - 1] - puzzles[i])
print(minimum)


(a, b) = (int(x) for x in input().split())
lc = list(map(int, input().split()))
l = sorted(lc)
mx = 0
mn = 0
lmin = list()
lmax = list()
x = 0
i = 0
ll = 0
for i in range(len(l)):
	lmin.append(l[i:i + a])
	if len(l) - i <= a:
		break
k = 0
for i in range(len(lmin)):
	mx = max(lmin[i])
	mn = min(lmin[i])
	lmax.append(mx - mn)
print(min(lmax))


(n, m) = [int(i) for i in input().split()]
l = [int(i) for i in input().split(' ')]
l = sorted(l)
result = 1001
for i in range(m - n + 1):
	diff = l[n + i - 1] - l[i]
	result = min(diff, result)
print(result)


def _min(a, b):
	if a < b:
		return a
	return b
(n, m) = tuple(map(int, input().split()))
li = list(map(int, input().split()))
li.sort()
best = 9999999
for k in range(0, m - n + 1):
	best = _min(best, li[k + n - 1] - li[k])
print(best)


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


(n, k) = [int(n) for n in input().split()]
brr = list(map(int, input().strip().split()))[:k]
arr = sorted(brr)
s = arr[k - 1] - arr[0]
for i in range(k - n + 1):
	d = arr[i + n - 1] - arr[i]
	if d <= s:
		s = d
	else:
		pass
print(s)


(n, m) = input().split()
n = int(n)
m = int(m)
lst = [int(x) for x in input().split()]
lst.sort()
sum = 10000
for i in range(m - n + 1):
	ha = lst[i + n - 1] - lst[i]
	sum = min(ha, sum)
print(int(sum))


(n, m) = map(int, input().split())
Ar = [int(x) for x in input().split()]
Ar.sort()
if m == n:
	print(max(Ar) - min(Ar))
	exit()
A = []
for i in range(m - n + 1):
	A.append(Ar[i + n - 1] - Ar[i])
print(min(A))


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
d = 9999999
for i in range(m - n + 1):
	b = a[i + n - 1] - a[i]
	if b < d:
		d = b
print(d)


from math import inf
(n, m) = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
y = inf
for i in range(m - n + 1):
	z = x[i:i + n]
	if y > z[n - 1] - z[0]:
		y = z[n - 1] - z[0]
print(y)


import sys

def solve(xs, n, m):
	xs.sort()
	return min((xs[i + n - 1] - xs[i] for i in range(m - n + 1)))

def print_stderr(*args, **kwargs):
	print(*args, file=sys.stderr, **kwargs)

def main():
	[n, m] = [int(i) for i in input().strip().split()]
	fs = [int(i) for i in input().strip().split()]
	assert len(fs) == m
	result = solve(fs, n, m)
	print(result)
main()


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
(i, j) = (0, n - 1)
ans = 1001
while j < m:
	if arr[j] - arr[i] < ans:
		ans = arr[j] - arr[i]
	i += 1
	j += 1
print(ans)


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
f.sort(reverse=True)
diff = f[0] - f[0 + n - 1]
for i in range(m - n + 1):
	diff = min(diff, f[i] - f[i + n - 1])
print(diff)


(n, m) = list(map(int, input().split()))
all_puzzles = list(map(int, input().split()))
all_puzzles.sort(reverse=True)
selection = list()
for possibilities in range(m - n + 1):
	selection.append(all_puzzles[possibilities] - all_puzzles[possibilities + n - 1])
print(min(selection))


(n, m) = map(int, input().split())
a = sorted([int(i) for i in input().split()])
s = 0
maxx = 1100
i = 0
while i < m - n + 1:
	s = a[i + n - 1] - a[i]
	maxx = min(maxx, s)
	i += 1
maxx = min(maxx, s)
print(maxx)


thing1 = input()
thing2 = input()
thing1 = thing1.split(' ')
n = int(thing1[0])
m = int(thing1[1])
puzzlesStr = thing2.split(' ')
puzzles = []
for term in puzzlesStr:
	puzzles += [int(term)]
puzzles.sort()
currentD = 0
bestD = puzzles[n - 1] - puzzles[0]
for i in range(m - n + 1):
	currentD = puzzles[n - 1 + i] - puzzles[i]
	if currentD < bestD:
		bestD = currentD
print(bestD)


l = list(map(int, input().split()))
n = l[0]
t = l[1]
x = list(map(int, input().split()))
x = sorted(x)
m = x[n - 1] - x[0]
for i in range(0, t):
	if n - 1 + i < t:
		tmp = x[n - 1 + i] - x[i]
		if tmp < m:
			m = tmp
print(m)


l = input().split()
tempArr = [int(x) for x in l]
(n, m) = tempArr
l = input().split()
initArr = [int(x) for x in l]
initArr.sort()
smallestDifference = initArr[n - 1] - initArr[0]
for i in range(1, m - n + 1):
	if initArr[i + n - 1] - initArr[i] < smallestDifference:
		smallestDifference = initArr[i + n - 1] - initArr[i]
print(smallestDifference)


n = list(map(int, input().split()))
m = list(map(int, input().split()))
m.sort()
min_i = 9999999999999999
for i in range(n[1] - n[0] + 1):
	min_i = min(min_i, m[i + n[0] - 1] - m[i])
if min_i == 9999999999999999:
	print(0)
else:
	print(min_i)


(n, m) = map(int, input().split())
p = sorted(map(int, input().split()))
x = 1001
for i in range(m - n + 1):
	if x > p[i + n - 1] - p[i]:
		x = p[i + n - 1] - p[i]
print(x)


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


inp = input().split()
n = int(inp[0])
m = int(inp[1])
k = sorted([int(x) for x in input().split()], reverse=True)
if len(k) < n:
	print(k[0] - k[-1])
else:
	smallest = k[0] - k[n - 1]
	for i in range(len(k) - n + 1):
		current = k[i] - k[n - 1 + i]
		if current < smallest:
			smallest = current
	print(smallest)


s = input().split(' ')
n = int(s[0])
m = int(s[1])
s = input().split(' ')
a = [0 for i in range(m)]
for i in range(m):
	a[i] = int(s[i])
a.sort()
minValue = a[n - 1] - a[0]
temp = 0
for i in range(0, m - n + 1):
	temp = a[i + n - 1] - a[i]
	if temp < minValue:
		minValue = temp
print(minValue)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
nl = []
l = sorted(l)
for i in range(len(l) - n + 1):
	d = l[i + n - 1] - l[i]
	nl.append(d)
print(min(nl))


a = list(map(int, input().rstrip().split()))
arr = list(map(int, input().rstrip().split()))
arr.sort()
diff = 0
min_sub = float('inf')
rang = a[1] - a[0]
for i in range(rang + 1):
	diff = arr[i + a[0] - 1] - arr[i]
	if diff < min_sub:
		min_sub = diff
print(min_sub)


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


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
min = 1000
for i in range(m - n + 1):
	b = a[i:i + n]
	if b[-1] - b[0] < min:
		min = b[-1] - b[0]
print(min)


import sys
(n, m) = map(int, sys.stdin.readline().split())
f = list(map(int, sys.stdin.readline().split()))
f = sorted(f)
min_dif = f[n - 1] - f[0]
for i in range(m - n + 1):
	dif = f[n - 1 + i] - f[i]
	if dif < min_dif:
		min_dif = dif
sys.stdout.write(str(min_dif))


(m, n) = map(int, input().split())
f = list(map(int, input().split()))
f.sort()
result = 1001
for i in range(n - m + 1):
	result = min(result, f[i + m - 1] - f[i])
print(result)


def fun(lst):
	res = 0
	for i in range(len(lst) - 1):
		res += lst[i] - lst[i + 1]
	return res
(n, m) = map(int, input().split())
f = sorted(list(map(int, input().split())), reverse=True)
delta = float('inf')
lst = []
for i in range(m - n + 1):
	if fun(f[i:i + n]) < delta:
		delta = fun(f[i:i + n])
		lst = f[i:i + n]
print(lst[0] - lst[-1])


(n, m) = [int(i) for i in input().split()]
puzzs = [int(i) for i in input().split()]
puzzs = sorted(puzzs)
min_ = puzzs[n - 1] - puzzs[0]
for i in range(len(puzzs) - n + 1):
	if puzzs[i + n - 1] - puzzs[i] < min_:
		min_ = puzzs[i + n - 1] - puzzs[i]
print(min_)


(n, m) = [int(x) for x in input().split()]
tab = [int(x) for x in input().split()]
tab.sort()
mini = 123520
for i in range(len(tab) - n + 1):
	if tab[i + n - 1] - tab[i] < mini:
		mini = tab[i + n - 1] - tab[i]
print(mini)


from math import floor, ceil
(n, m) = input().split()
n = int(n)
m = int(m)
l = [int(x) for x in input().split()]
best = 1001
l = sorted(l)
for i in range(m - n + 1):
	best = min(best, l[i + n - 1] - l[i])
print(best)


(N, M) = list(map(int, input().split(' ')))
puzzles = list(map(int, input().split(' ')))
puzzles.sort()
ans = 100000000000
for i in range(N - 1, M):
	ans = min(ans, puzzles[i] - puzzles[i - N + 1])
print(ans)


(n, m) = map(int, input().split())
pieces = [int(x) for x in input().split()]
pieces.sort()
min_diff = 2048
for i in range(m - n + 1):
	diff = pieces[i + n - 1] - pieces[i]
	min_diff = min(min_diff, diff)
print(min_diff)


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
mn = 999999999999
for i in range(m - n + 1):
	if arr[n - 1 + i] - arr[i] < mn:
		mn = arr[n - 1 + i] - arr[i]
print(mn)


(m, n) = map(int, input().split())
lst = [int(x) for x in input().split()]
lst = sorted(lst)
mst = [lst[i + m - 1] - lst[i] for i in range(0, n - m + 1)]
print(min(mst))


class Code:

	def __init__(self):
		(self.n, self.m) = list(map(int, input().split()))
		self.arr = list(map(int, input().split()))

	def process(self):
		self.arr.sort()
		a = self.arr
		b = self.arr[self.n - 1:]
		print(min([j - i for (i, j) in zip(a, b)]))
code = Code()
code.process()


s = str(input()).split()
n = int(s[0])
m = int(s[1])
s = str(input()).split()
f = [int(ss) for ss in s]
f.sort()
curr_min = f[-1] - f[0]
for i in range(0, m - n + 1):
	diff = f[i + n - 1] - f[i]
	if diff < curr_min:
		curr_min = diff
print(curr_min)


(n, m) = [int(x) for x in input().split()]
a = [int(z) for z in input().split()]
c = []
a.sort(reverse=False)
for i in range(m - n + 1):
	k = a[i + n - 1] - a[i]
	c.append(k)
print(min(c))


f = input().split(' ')
g = list(map(int, f))
h = input().split(' ')
i = list(map(int, h))
i.sort()
diff = i[g[0] - 1] - i[0]
for k in range(g[1] - g[0] + 1):
	if i[k + g[0] - 1] - i[k] < diff:
		diff = i[k + g[0] - 1] - i[k]
print(diff)


class Solution:

	def __init__(self):
		(self.n, self.m) = map(int, input().split())
		self.f = sorted(list(map(int, input().split())))

	def solution(self):
		best = 1001
		for i in range(self.m - self.n + 1):
			best = min(best, self.f[i + self.n - 1] - self.f[i])
		print(best)

def main():
	ob = Solution()
	ob.solution()
main()


from math import inf
(n, m) = map(int, input().split())
f = list(map(int, input().split()))
f.sort()
result = inf
for i in range(m - n + 1):
	dif = f[i + n - 1] - f[i]
	if dif < result:
		result = dif
print(result)


(n, m) = map(int, input().split())
k = list(map(int, input().split()))
l = sorted(k)
p = 0
res = max(l)
for i in range(n, len(l) + 1):
	v = l[p:i]
	s = max(v) - min(v)
	if s < res:
		res = s
	p = p + 1
print(res)


(n, k) = input().split()
arr = list(map(int, input().strip().split()))
arr.sort()
i = int(n)
res = float('inf')
while i <= int(k):
	res = min(res, arr[i - 1] - arr[i - int(n)])
	i += 1
print(res)


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
f = sorted(f)
ans = f[-1]
for i in range(m - n + 1):
	diff = f[i + n - 1] - f[i]
	if diff < ans:
		ans = diff
print(ans)


(x, y) = map(int, input().split())
max = 999999999999
num = list(map(int, input().split()))
num = sorted(num)
for i in range(0, y - x + 1):
	if num[i + x - 1] - num[i] < max:
		max = num[i + x - 1] - num[i]
print(max)


(n, m) = map(int, input().split())
a = [int(x) for x in input().split()]
a.sort(reverse=True)
min_diff = 1001
for i in range(m - n + 1):
	if min_diff > a[i] - a[i + n - 1]:
		min_diff = a[i] - a[i + n - 1]
if min_diff == 1001:
	print(0)
else:
	print(min_diff)


(n, m) = map(int, input().split())
k = list(map(int, input().split()))
k.sort()
ans = 10000
c = 0
N = n - 1
while N < m:
	d = int(k[N]) - int(k[c])
	if d < ans:
		ans = d
	c += 1
	N += 1
print(ans)


(n, m) = [int(i) for i in input().split()]
list = [int(i) for i in input().split()]
list.sort()
y = 1001
for i in range(m - n + 1):
	x = list[i + n - 1] - list[i]
	if x < y:
		y = x
print(y)


(m, n) = [int(x) for x in input().split()]
x = sorted(map(int, input().split()))
y = [x[i + m - 1] - x[i] for i in range(n - m + 1)]
y.sort()
print(y[0])


(r, n) = map(int, input().split(' '))
arr = [int(i) for i in input().split(' ')]
arr.sort()
diff = 200000.0
for i in range(n - r + 1):
	if arr[i + r - 1] - arr[i] < diff:
		diff = arr[i + r - 1] - arr[i]
print(diff)


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
minn = float('inf')
arr.sort()
for x in range(m - n + 1):
	a = arr[x + n - 1] - arr[x]
	minn = min(minn, a)
print(minn)


(n, m) = map(int, input().split())
ls = list(map(int, input().split()))
x = m - n
res = 1000
ls.sort()
for y in range(x + 1):
	res1 = ls[y + (n - 1)] - ls[y]
	if res1 < res:
		res = res1
print(res)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 1001
for i in range(m - n + 1):
	if a[i + n - 1] - a[i] < ans:
		ans = a[i + n - 1] - a[i]
print(ans)


a = list(map(int, input().split()))
b = sorted(list(map(int, input().split())))
c = 10 ** 100
for i in range(a[1] - a[0] + 1):
	d = b[i + a[0] - 1] - b[i]
	if d < c:
		c = d
print(c)


(n, m) = map(int, input().split())
puzzles = [int(i) for i in input().split()]
puzzles.sort()
min_dif = 1001
for i in range(m - n + 1):
	if puzzles[i + n - 1] - puzzles[i] < min_dif:
		min_dif = puzzles[i + n - 1] - puzzles[i]
print(min_dif)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
a.reverse()
mas = []
for i in range(m - n + 1):
	mas.append(abs(a[i] - a[i + n - 1]))
print(min(mas))


s = input()
s1 = s.split()
n = int(s1[0])
n1 = int(s1[1])
s3 = input().split()
lt = list(map(int, s3))
lt.sort()
min = max(lt)
for i in range(0, n1 - n + 1):
	if lt[i + n - 1] - lt[i] <= min:
		min = lt[i + n - 1] - lt[i]
print(min)


(n, m) = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
arr.sort()
mini = 9999999
for i in range(m - n + 1):
	mini = min(mini, arr[i + n - 1] - arr[i])
print(mini)


(s, n) = list(map(int, input().split()))
l = list(map(int, input().split()))
l.sort()
min = 1000
for i in range(len(l) - (s - 1)):
	diff = l[i + (s - 1)] - l[i]
	if min > diff:
		min = diff
	else:
		continue
print(min)


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


(n, m) = map(int, input().split())
f = 1001
a = sorted(list(map(int, input().split())))
for i in range(m - n + 1):
	f = min(abs(a[i] - a[i + n - 1]), f)
print(f)


(a, b) = map(int, input().split())
l1 = list(map(int, input().split()))
l1 = sorted(l1)
m = 1000
for i in range(b - a + 1):
	d = l1[i + a - 1] - l1[i]
	if d < m:
		m = d
print(m)


(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
i = 0
j = i + n - 1
md = 1000000000
while j <= m - 1:
	md = min(md, a[j] - a[i])
	i = i + 1
	j = j + 1
print(md)


(students, puzzles) = map(int, input().split())
quantity = list(map(int, input().split()))
quantity.sort()
repeated = []
counter = 1
for x in range(len(quantity) - 1):
	if quantity[x] == quantity[x + 1]:
		counter += 1
	else:
		repeated.append(counter)
		counter = 1
repeated.append(counter)
if max(repeated) >= students:
	print(0)
else:
	best = max(quantity)
	try:
		for x in range(len(quantity) - 1):
			best = min(best, quantity[x + students - 1] - quantity[x])
	except IndexError:
		pass
	print(best)


nm = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
b = []
for i in range(nm[1]):
	if i + nm[0] > nm[1]:
		break
	else:
		b.append(a[i + nm[0] - 1] - a[i])
print(min(b))


(n, m) = map(int, input().split())
a = sorted(list(map(int, input().split())))
diff = []
i = 0
while i < m - n + 1:
	diff.append(a[i + n - 1] - a[i])
	i += 1
print(min(diff))


(n, m) = map(int, input().split())
pieces = [int(x) for x in input().split()]
for i in range(m):
	x = i
	while pieces[x] < pieces[x - 1] and x > 0:
		(pieces[x], pieces[x - 1]) = (pieces[x - 1], pieces[x])
		x -= 1
mi = pieces[n - 1] - pieces[0]
for j in range(m + 1 - n):
	dif = pieces[j + n - 1] - pieces[j]
	if dif < mi:
		mi = dif
print(mi)


(a, b) = map(int, input().split())
l = sorted(list(map(int, input().split())))
z = []
for i in range(b - a + 1):
	z.append(l[i + a - 1] - l[i])
print(min(z))


(n, m) = [int(x) for x in input().split()]
puzzles = [int(x) for x in input().split()]
puzzles.sort()
d = puzzles[n - 1] - puzzles[0]
for i in range(1, m - n + 1):
	D = puzzles[i + n - 1] - puzzles[i]
	d = min(d, D)
print(d)


(n, m) = [int(x) for x in input().split()]
arr = sorted([int(x) for x in input().split()])
mn = 100000
for i in range(m - n + 1):
	if arr[i + n - 1] - arr[i] < mn:
		mn = arr[i + n - 1] - arr[i]
print(mn)


(n, m) = map(int, input().split(' '))
pieces = list(map(int, input().split(' ')))
pieces.sort()
leastDif = pieces[-1] - pieces[0]
for i in range(0, m - n + 1):
	actualDif = pieces[n - 1 + i] - pieces[i]
	if actualDif < leastDif:
		leastDif = actualDif
print(leastDif)


(n, m) = map(int, input().split())
ans = 1000
f = sorted([int(_) for _ in input().split()])
for i in range(m - n + 1):
	ans = min(ans, f[i + n - 1] - f[i])
print(ans)


(n, m) = map(int, input().split())
puzzles = list(map(int, input().split()))
puzzles = sorted(puzzles)
diffs = []
for i in range(len(puzzles) - n + 1):
	diffs.append(puzzles[i + n - 1] - puzzles[i])
print(min(diffs))


(n, m) = input().split(' ')
n = int(n)
m = int(m)
b = []
b = list(map(int, input().split()))
b.sort()
d = b[n - 1] - b[0]
for i in range(1, m - n + 1):
	c = b[n - 1 + i] - b[0 + i]
	if c < d:
		d = c
print(d)


from itertools import combinations

def equally():
	(n, m) = list(map(int, input().split()))
	f = list(map(int, input().split()))
	f.sort()
	smallest = 10000
	for k in range(0, m - n + 1):
		smallest = min(smallest, f[k + n - 1] - f[k])
	print(smallest)
equally()


(num, n) = [int(x) for x in input().split()]
line = sorted([int(x) for x in input().split()])
min_dif = line[-1] - line[0]
for i in range(n - num + 1):
	dif = abs(line[i] - line[i + num - 1])
	if dif < min_dif:
		min_dif = dif
print(min_dif)


import math
(n, m) = map(int, input().split())
l = sorted(list(map(int, input().split())))
min1 = 5000
for i in range(len(l)):
	if i + n - 1 > len(l) - 1:
		break
	min1 = min(min1, l[i + n - 1] - l[i])
print(str(min1))


(n, m) = input().split(' ')
list_of_puzz = list(map(int, input().split(' ')))
list_of_puzz.sort()
n = int(n)
m = int(m)
smallest = 10000000
for i in range(0, m - n + 1):
	if smallest > list_of_puzz[i + n - 1] - list_of_puzz[i]:
		smallest = list_of_puzz[i + n - 1] - list_of_puzz[i]
print(smallest)


from sys import stdin as si
from collections import Counter as c
from sys import maxsize as mx

class Solution:

	def bazinga(self, n, m, l):
		l.sort()
		d = mx
		for i in range(0, m - n + 1):
			d = min(d, l[i + n - 1] - l[i])
		return d
(n, m) = map(int, si.readline().strip().split())
l = list(map(int, si.readline().strip().split()))
S = Solution()
print(S.bazinga(n, m, l))


def main():
	(n, m) = map(int, input().split())
	p = [int(x) for x in input().split()]
	p.sort()
	i = 0
	j = m - 1
	while j - i + 1 > n:
		if p[i + n - 1] - p[i] >= p[j] - p[j - n + 1]:
			i += 1
		else:
			j -= 1
	res = p[i:j + 1]
	print(max(res) - min(res))
main()


(n, m) = map(int, input().split(' '))
li = sorted(list(map(int, input().split(' '))))
min = 1000
for i in range(m - n + 1):
	if min > li[i + n - 1] - li[i]:
		min = li[i + n - 1] - li[i]
print(min)


(x, y) = map(int, input().split())
b = input().split()
for i in range(y):
	b[i] = int(b[i])
b.sort()
smallest = 1000000
for i in range(y - x + 1):
	small = b[i + x - 1] - b[i]
	if small < smallest:
		smallest = small
print(smallest)


a = input()
b = a.split(' ')
n = int(b[0])
m = int(b[1])
a = input()
b = a.split(' ')
f = []
for i in range(m):
	f.append(int(b[i]))
for i in range(m - 1):
	for j in range(i + 1, m):
		if f[i] > f[j]:
			t = f[i]
			f[i] = f[j]
			f[j] = t
ans = 1000
for i in range(m - n + 1):
	if abs(f[i] - f[i + n - 1]) < ans:
		ans = abs(f[i] - f[i + n - 1])
print(ans)


def insertsort(list):
	for i in range(1, len(list)):
		j = i
		while j > 0 and list[j - 1] > list[i]:
			j -= 1
		list.insert(j, list[i])
		list.pop(i + 1)
	return list
(n, m) = map(int, input().split())
list1 = list(map(int, input().split()))
list1 = insertsort(list1)
mini = max(list1) - min(list1)
for i in range(len(list1) - n + 1):
	if list1[i + n - 1] - list1[i] < mini:
		mini = list1[i + n - 1] - list1[i]
print(mini)


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
mindiff = float('inf')
for i in range(m - n + 1):
	mindiff = min(mindiff, arr[i + n - 1] - arr[i])
print(mindiff)


def main():
	(n, m) = input().split()
	pieceCnt = input().split()
	pieceCnt = list(map(int, pieceCnt))
	(n, m) = (int(n), int(m))
	pieceCnt.sort()
	minDif = 9999999
	for i in range(m - (n - 1)):
		if pieceCnt[i + (n - 1)] - pieceCnt[i] < minDif:
			minDif = pieceCnt[i + (n - 1)] - pieceCnt[i]
	if minDif == 9999999:
		minDif = pieceCnt[len(pieceCnt) - 1] - pieceCnt[0]
	print(minDif)
main()


(n, m) = map(int, input().split())
f = sorted(list(map(int, input().split())))
mi = float('inf')
j = 0
for i in range(n - 1, m):
	mi = min(mi, f[i] - f[j])
	j += 1
print(mi)


(n, m) = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
p.sort()
res = 1000
for i in range(m - n + 1):
	l = p[i + n - 1] - p[i]
	if l < res:
		res = l
print(res)


f = lambda : map(int, input().split())
(n, m) = f()
a = sorted(f())
mi = 2000
for i in range(m - n + 1):
	if abs(max(a[i:i + n]) - min(a[i:i + n])) < mi:
		mi = abs(max(a[i:i + n]) - min(a[i:i + n]))
print(mi)


(n, m) = map(int, input().split())
a = [int(x) for x in input().split()]
a.sort()
b = []
i = 0
while n + i - 1 < m:
	b.append(a[n + i - 1] - a[i])
	i += 1
b.sort()
print(b[0])


(n, m) = map(int, input().split(' '))
l = list(map(int, input().split(' ')))
l.sort()
r = 1996
for i in range(0, m - n + 1):
	r = min(r, l[i + n - 1] - l[i])
print(r)


(n, m) = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
p.sort()
difference_list = [abs(p[x] - p[x + 1]) for x in range(m - 1)]
new_l = [difference_list[x:x + n - 1] for x in range(m - n + 1)]
print(min([sum(x) for x in new_l]))


(n, m) = list(map(int, input().split()))
nums = list(map(int, input().split()))
nums.sort()
best = float('inf')
for i in range(m - n + 1):
	best = min(best, nums[i + n - 1] - nums[i])
print(best)


(n, a) = map(int, input().split())
L = sorted(list(map(int, input().split())))
minimo = L[n - 1] - L[0]
i = 1
for k in range(n, a):
	if L[k] - L[i] < minimo:
		minimo = L[k] - L[i]
	i += 1
print(minimo)


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


(n, m) = map(int, input().split())
puzzles = list(map(int, input().strip().split()))[:m]
puzzles = sorted(puzzles)
diff = []
for i in range(0, m - n + 1):
	res = puzzles[n + i - 1] - puzzles[i]
	diff.append(res)
print(min(diff))


(n, m) = map(int, input().split())
puzzle = list(map(int, input().split()))
puzzle.sort()
least_diff = puzzle[len(puzzle) - 1] - puzzle[0]
for i in range(m - n + 1):
	if puzzle[i + n - 1] - puzzle[i] < least_diff:
		least_diff = puzzle[i + n - 1] - puzzle[i]
print(least_diff)


(n, m) = map(int, input().split())
l = sorted(list(map(int, input().split())))
p = l[:n]
Q = p[-1] - p[0]
for i in range(n, m):
	del p[0]
	p.append(l[i])
	if Q > p[-1] - p[0]:
		Q = p[-1] - p[0]
print(Q)


import math
n = input()
num = input()
arr1 = []
arr2 = []

def get_the_list(count, inn, arr):
	for i in range(0, len(inn)):
		if inn[i] == ' ':
			arr.append(int(inn[count:i]))
			count = i + 1
		elif i == len(inn) - 1:
			arr.append(int(inn[count:len(inn) + 1]))
	return arr
inn1 = get_the_list(0, n, arr1)
inn2 = get_the_list(0, num, arr2)
inn2.sort()
result = math.inf
for i in range(0, len(inn2) - inn1[0] + 1):
	result_diff = arr2[i + inn1[0] - 1] - arr2[i]
	if result_diff < result:
		result = result_diff
print(result)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
res = 10 ** 5
for i in range(m - n + 1):
	res = min(res, a[i + n - 1] - a[i])
print(res)


(x, y) = input().split()
a = int(x)
b = int(y)
arr = [int(i) for i in input().split()]
value = 99999
arr.sort()
for i in range(0, b - a + 1):
	if arr[i + a - 1] - arr[i] < value:
		value = arr[i + a - 1] - arr[i]
print(value)


(n, m) = map(int, input().split())
arr = sorted(map(int, input().split()))
mini = 999999999
for j in range(m - n + 1):
	if arr[j + n - 1] - arr[j] < mini:
		mini = arr[j + n - 1] - arr[j]
print(mini)


(n, m) = map(int, input().split())
lst = list(map(int, input().split()))
lst.sort()
smallest = 1000
for i in range(m - n + 1):
	sub = lst[i + n - 1] - lst[i]
	if sub < smallest:
		smallest = sub
print(smallest)


(n, t) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
d = 1000
for i in range(t - n + 1):
	if l[i + n - 1] - l[i] < d:
		d = l[i + n - 1] - l[i]
print(d)


(n, m) = map(int, input().split())
f = sorted(list(map(int, input().split())))
suma = []
solution = 1000
(count, i, j) = (0, 0, 0)
while True:
	suma.append(f[i])
	count += 1
	if count == n:
		solution = min(solution, max(suma) - min(suma))
		suma = []
		i = j
		j += 1
		count = 0
	i += 1
	if i == m:
		break
print(solution)


inStr = input()
n = int(inStr.split()[0])
m = int(inStr.split()[1])
intev = n - 1
jugStr = input()
jugList = jugStr.split()
jugSaw = [0] * len(jugList)
for i in range(m):
	jugSaw[i] = int(jugList[i])
jugSaw.sort()
i = 0
diffMin = 1000
for i in range(m):
	if i + intev >= m:
		break
	diff = jugSaw[i + intev] - jugSaw[i]
	if diff < diffMin:
		diffMin = diff
	i = i + 1
print(diffMin)


(n, m) = map(int, input().split())
f = sorted(map(int, input().split()))
i = -1
j = n - 1
l = []
while j < m:
	c = max(f[i + 1:j + 1]) - min(f[i + 1:j + 1])
	l.append(c)
	i += 1
	j += 1
print(min(l))


(n, m) = map(int, input().split())
a = sorted(list(map(int, input().split())))
x = []
for y in range(0, m - n + 1):
	x.append(a[n + y - 1] - a[y])
print(min(x))


__author__ = 'widoc'
(n, m) = map(int, input().split())
fi = list(map(int, input().split()))
fi = sorted(fi)
cur_min = 50 * 1000
for i in range(m - n + 1):
	t = fi[i + n - 1] - fi[i]
	if t < cur_min:
		cur_min = t
print(cur_min)


(n, m) = input().split()
a = sorted(list(map(int, input().split())))
output = []
for i in range(0, int(m) - int(n) + 1):
	output.append(a[i + int(n) - 1] - a[i])
print(min(output) if len(output) > 0 else 0)


(n, m) = map(int, input().split())
a = sorted([int(x) for x in input().split()])
k = 1000000
for i in range(m - n + 1):
	k = min(k, a[i + n - 1] - a[i])
print(k)


a = input().split(' ')
n = int(a[0])
m = int(a[1])
a = input().split(' ')
for i in range(len(a)):
	a[i] = int(a[i])
a.sort()
if n == m:
	print(a[-1] - a[0])
	exit(0)
r = a[n - 1] - a[0]
i = n
while i <= m:
	r = min(r, a[i - 1] - a[i - n])
	i += 1
print(r)


data = input().split()
n = int(data[0])
m = int(data[1])
lista = list(map(int, input().split()))
lista.sort(reverse=True)
minimum = lista[0] - lista[n - 1]
for i in range(1, len(lista) - (n - 1)):
	if minimum > lista[i] - lista[i + n - 1]:
		minimum = lista[i] - lista[i + n - 1]
print(minimum)


l = list(map(int, input().strip().split()))
n = l[0]
m = l[1]
f = list(map(int, input().strip().split()))
if n == m:
	print(max(f) - min(f))
else:
	count = 10 ** 10
	f.sort()
	for i in range(0, m - n + 1):
		a = f[i]
		b = f[i + n - 1]
		count = min(count, b - a)
	print(count)


(n, m) = map(int, input().split())
a = list(map(int, input().strip().split()))
a.sort()
mi = 10000
for i in range(m - n + 1):
	mi = min(mi, max(a[i:i + n]) - min(a[i:i + n]))
print(mi)


(n, m) = map(int, input().split())
puzzles = [int(x) for x in input().split()]
puzzles.sort()
best = 1001
for x in range(m - n + 1):
	best = min(best, puzzles[x + n - 1] - puzzles[x])
print(best)


(n, m) = map(int, input().split())
pieces = [int(i) for i in input().split()]
pieces.sort()
min_diff = 1000
for i in range(m - n + 1):
	min_diff = min(min_diff, pieces[i + n - 1] - pieces[i])
print(min_diff)


(n, m) = [int(e) for e in input().split()]
lis = [int(e) for e in input().split()]
lis.sort()
mini = 100000
for i in range(m - n + 1):
	d = lis[i + n - 1] - lis[i]
	mini = min(d, mini)
print(mini)


(a, b) = [int(x) for x in input().split()]
n = [int(x) for x in input().split()]
n.sort()
m = int(n[a - 1]) - int(n[0])
for i in range(b - a + 1):
	if m > n[i + a - 1] - n[i]:
		m = n[i + a - 1] - n[i]
print(m)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
x = 0
m = a[n - 1] - a[0]
while x < len(a) - n + 1:
	m = min(m, a[x + n - 1] - a[x])
	x += 1
print(m)


(n, m) = [int(x) for x in input().split()]
f = sorted([int(x) for x in input().split()])
c = []
for i in range(m - n + 1):
	a = f[i + n - 1] - f[i]
	c.append(a)
print(min(c))


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
k = []
for i in range(len(a) - n + 1):
	for j in range(n):
		t = a[i:n + i]
		s = max(t) - min(t)
		k.append(s)
print(min(k))


def Main():
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	ans = 1001
	for i in range(m - n + 1):
		if ans > arr[i + n - 1] - arr[i]:
			ans = arr[i + n - 1] - arr[i]
	print(ans)
Main()


(n, m) = input().split()
l = input().split()
n = int(n)
ans = 10000
for i in range(0, int(m)):
	l[i] = int(l[i])
l.sort()
for i in range(0, int(m) - int(n) + 1):
	if ans > l[i + n - 1] - l[i]:
		ans = l[i + n - 1] - l[i]
print(ans)


(n, m) = map(int, input().split())
puzzles = sorted([int(x) for x in input().split()])
minimum = []
for i in range(m - n + 1):
	opt = puzzles[i:i + n]
	minimum.append(max(opt) - min(opt))
print(min(minimum))


(n, m) = [int(a) for a in input().split()]
f = [int(a) for a in input().split()]
f.sort()
diff = 100000000000000000000
for i in range(n - 1, m):
	diff = min(diff, f[i] - f[i + 1 - n])
print(diff)


(n, m) = input().split()
n = int(n)
m = int(m)
s = input().split()
for i in range(m):
	s[i] = int(s[i])
s.sort()
mini = 1000
for i in range(m - n + 1):
	if s[i + n - 1] - s[i] <= mini:
		mini = s[i + n - 1] - s[i]
print(mini)


def findDiff(a):
	return max(a) - min(a)
(n, m) = map(int, input().split())
f = list(map(int, input().split()))
f.sort()
diff = findDiff(f)
for i in range(len(f) - n + 1):
	x = findDiff(f[i:i + n])
	if diff > x:
		diff = x
print(diff)


(n, m) = tuple(map(int, input().split()))
f = list(map(int, input().split()))
f.sort()
differences = []
for i in range(0, len(f) - n + 1):
	difference = f[i + n - 1] - f[i]
	differences.append(difference)
print(min(differences))


p = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))
m = a[p[0] - 1] - a[0]
i = 1
while i + p[0] - 1 < len(a):
	if a[i + p[0] - 1] - a[i] < m:
		m = a[i + p[0] - 1] - a[i]
	i += 1
print(m)


inputArray = input().split(' ')
piecesArray = input().split(' ')
piecesArray.sort(key=int)
minDist = 1000
for i in range(int(inputArray[1]) - int(inputArray[0]) + 1):
	maybeDist = int(piecesArray[i + int(inputArray[0]) - 1]) - int(piecesArray[i])
	if maybeDist < minDist:
		minDist = maybeDist
print(minDist)


(student, puzzles) = map(int, input().split())
puz_lst = list(map(int, input().split()))
puz_lst_sort = sorted(puz_lst)
difference = puz_lst_sort[student - 1] - puz_lst_sort[0]
for i in range(1, len(puz_lst_sort) - student + 1):
	temp_difference = puz_lst_sort[i + student - 1] - puz_lst_sort[i]
	if temp_difference < difference:
		difference = temp_difference
print(difference)


string = input().split()
size = int(string[0])
nos = int(string[1])
puzzles = input().split()
puzzles2 = []
diffs = []
for p in puzzles:
	puzzles2.append(int(p))
puzzles2.sort()
i = 0
while i <= nos - size:
	diffs.append(puzzles2[i + size - 1] - puzzles2[i])
	i += 1
print(min(diffs))


(x, y) = map(int, input().split())
l = list(map(int, input().split()))
l = sorted(l)
m = 1000
for i in range(y - x + 1):
	d = l[i + x - 1] - l[i]
	if d < m:
		m = d
print(m)


(n, m) = [int(x) for x in input().strip().split()]
arr = [int(x) for x in input().strip().split()]
arr = sorted(arr)
ans = arr[n - 1] - arr[0]
for i in range(m - n + 1):
	temp = arr[i + n - 1] - arr[i]
	ans = min(ans, temp)
print(ans)


(n, m) = [int(_) for _ in input().split()]
f = sorted([int(_) for _ in input().split()])
print(min([f[i - 1] - f[i - n] for i in range(n, m + 1)]))


(n, m) = [*map(int, input().split())]
a = sorted([*map(int, input().split())])
ans = a[n - 1] - a[0]
for i in range(m - n + 1):
	wk1 = a[i + n - 1] - a[i]
	if wk1 < ans:
		ans = wk1
print(ans)


(n, m) = [int(x) for x in input().split()]
N = sorted([int(x) for x in input().split()])
final_difference = 10000
for start_index in range(0, m - n + 1):
	temp_difference = N[n - 1 + start_index] - N[start_index]
	if temp_difference < final_difference:
		final_difference = temp_difference
print(final_difference)


(n, m) = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
l = sorted(l)
s = l[n - 1] - l[0]
for i in range(m - n + 1):
	if l[n - 1 + i] - l[i] < s:
		s = l[n - 1 + i] - l[i]
print(s)


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


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


(n, m) = [int(i) for i in input().split()]
sizes = [int(i) for i in input().split()]
sizes.sort()
diff = 1000
for i in range(0, m - n + 1):
	diff = diff if diff < sizes[i + n - 1] - sizes[i] else sizes[i + n - 1] - sizes[i]
print(diff)


(n, m) = input().split()
n = int(n)
m = int(m)
answer = []
list1 = [int(x) for x in input().split()]
list1.sort()
for i in range(m - n + 1):
	list2 = list1[i:n + i]
	answer.append(max(list2) - min(list2))
print(min(answer))


(a, b) = input().split()
a = int(a, 10)
b = int(b, 10)
s = input().split()
s1 = list(s)
for i in range(len(s)):
	s1[i] = int(s1[i])
h = 0
temp = 0
s1 = sorted(s1)
base = s1[a - 1] - s1[0]
for i in range(b - a + 1):
	h = s1[i + a - 1] - s1[i]
	if h < base:
		base = h
print(base)


(n, k) = map(int, input().split())
asd = [int(k) for k in input().split()]
asd.sort()
qwe = 10000000000000
for i in range(k - n + 1):
	ppp = asd[i + n - 1] - asd[i]
	if ppp < qwe:
		qwe = ppp
	else:
		pass
print(qwe)


(N, M) = list(map(int, input().split()))
puzzles = list(map(int, input().split()))
puzzles.sort()
span = M - N + 1
diff = 10000
for x in range(span):
	diff = min(diff, puzzles[x + N - 1] - puzzles[x])
print(diff)


(n, m) = map(int, input().split())
(numbers, dif) = (sorted((int(i) for i in input().split())), 2000)
for i in range(m - n + 1):
	dif = min(dif, numbers[i + n - 1] - numbers[i])
print(dif)


sa = input().split(' ')
puzzles = int(sa[0])
sa2 = input().split(' ')
sa3 = [int(x) for x in sa2]
sa3.sort()
answer = 10000
for x in range(0, len(sa3) - puzzles + 1):
	answer = min(answer, abs(sa3[x] - sa3[x + puzzles - 1]))
print(answer)


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
(n, m) = I()
l = I()
l.sort()
ans = MOD
for i in range(n - 1, m):
	ans = min(ans, l[i] - l[i - n + 1])
print(ans)


(n, m) = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
p.sort()
ans = 1000
for i in range(0, m - n + 1):
	d = p[i + n - 1] - p[i]
	if d < ans:
		ans = d
print(ans)


(n, m) = input().split()
n = int(n)
m = int(m)
s = input()
l = [int(num) for num in s.split(' ')]
l.sort()
d = 1000000000
for i in range(m):
	j = i + n - 1
	if j < m:
		k = l[j] - l[i]
		if k < d:
			d = k
	else:
		break
print(d)


from sys import stdin, stdout, stderr, setrecursionlimit
setrecursionlimit(100000)

def debug(*e):
	if not __debug__:
		print(*e, file=stderr)

def dd(*vals):
	import inspect, re
	frame = inspect.getframeinfo(inspect.stack()[1][0])
	vs = re.search('dd\\((.+)\\)', frame.code_context[0]).group(1).split(',')
	if vs:
		debug(','.join(('{0} = {1}'.format(vs[i], v) for (i, v) in enumerate(vals))))

def trace(f):

	def traced(*args, **kw):
		debug('calling {} with args {}, {}'.format(f.__name__, args, kw))
		return f(*args, **kw)
	return traced

def read():
	return stdin.readline().rstrip()

def readarr(sep=None, maxsplit=-1):
	return read().split(sep, maxsplit)

def readint():
	return int(read())

def readintarr(sep=None, maxsplit=-1):
	return [int(a) for a in readarr(sep, maxsplit)]

def write(*args, **kwargs):
	sep = kwargs.get('sep', ' ')
	end = kwargs.get('end', '\n')
	stdout.write(sep.join((str(a) for a in args)) + end)

def writearr(arr, sep=' ', end='\n'):
	stdout.write(sep.join((str(a) for a in arr)) + end)
from itertools import combinations
from math import inf
(n, m) = readintarr()
ps = readintarr()
ps.sort()
mn = inf
for i in range(0, m):
	c = ps[i:i + n]
	dd(c)
	if len(c) < n:
		break
	v = c[-1] - c[0]
	if v < mn:
		r = c
		mn = v
write(mn)


info = input().split(' ')
students = int(info[0])
puzzles = int(info[1])
pieces = input().split(' ')
pieces = [int(i) for i in pieces]
pieces = sorted(pieces)
difference = []
i = 0
while students + i <= puzzles:
	window = pieces[i:students + i]
	value = int(max(window) - min(window))
	difference.append(value)
	i += 1
print(min(difference))


(n, m) = map(int, input().split())
size = map(int, input().split())
size = list(size)
size.sort()
t = size[n - 1] - size[0]
for i in range(m - n + 1):
	temp = size[i + n - 1] - size[i]
	if temp < t:
		t = temp
print(t)


(num_students, num_puzzles) = [int(a) for a in input().split()]
puzzle_pieces = [int(a) for a in input().split()]
puzzle_pieces.sort()
smallest_diff_so_far = float('inf')
for x in range(num_puzzles - num_students + 1):
	slice = puzzle_pieces[x:x + num_students]
	diff = slice[-1] - slice[0]
	if diff < smallest_diff_so_far:
		smallest_diff_so_far = diff
print(smallest_diff_so_far)


(n, m) = tuple(map(int, input().split()))
puzzles = list(sorted(list(map(int, input().split()))))
min = puzzles[n - 1] - puzzles[0]
for i in range(m - n):
	if min > puzzles[i + n] - puzzles[i + 1]:
		min = puzzles[i + n] - puzzles[i + 1]
print(min)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
mn = a[0] - a[n - 1]
i = 1
while i + n - 1 < m:
	t = a[i] - a[i + n - 1]
	if t < mn:
		mn = t
	i = i + 1
print(mn)


(k, j) = input().split()
n = int(k)
m = int(j)
d = []
x = input()
for i in x.split():
	d.append(int(i))
d.sort()
temp = d[n - 1] - d[0]
for i in range(m - 1):
	for j in range(i + (n - 1), m - 1):
		maxa = d[j + 1] - d[i + 1]
		if maxa < temp:
			temp = maxa
		break
print(temp)


(n, m) = [int(x) for x in input().split()]
f = [int(x) for x in input().split()]
f.sort()
l = [0] * (m - n + 1)
if n == m:
	print(f[n - 1] - f[0])
else:
	for i in range(m - n + 1):
		l[i] = f[i + n - 1] - f[i]
	l.sort()
	print(l[0])


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


row = str(input()).split(' ')
n = int(row[0])
pzz = list(map(int, str(input()).split(' ')))
pzz.sort()
aux = 100000000000000
for i in range(0, len(pzz) - n + 1):
	if pzz[n - 1 + i] - pzz[i] < aux:
		aux = pzz[n - 1 + i] - pzz[i]
print(aux)


(n, m) = map(int, input().split())
q = list(map(int, input().split()))
z = 100000
q.sort()
for i in range(m):
	if i + n <= m:
		a = [q[x] for x in range(i, i + n)]
		if max(a) - min(a) < z:
			z = max(a) - min(a)
print(z)


(n, m) = map(int, input().split())
f = [int(i) for i in input().split()]
f_sorted = sorted(f)
li = []
for i in range(0, m - n + 1):
	dif = f_sorted[i + n - 1] - f_sorted[i]
	li.append(dif)
print(min(li))


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
f.sort()
cnt = 100000000
for i in range(m - n + 1):
	cnt = min(cnt, f[i + n - 1] - f[i])
print(cnt)


(n, m) = map(int, input().split())
list1 = list(map(int, input().split()))
list1.sort()
diff = max(list1) + 1
for x in range(m - n + 1):
	diff = min(diff, list1[x + n - 1] - list1[x])
print(diff)


import sys
(children, size) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
diff = sys.maxsize
for i in range(0, size - children + 1):
	if arr[i + children - 1] - arr[i] < diff:
		diff = arr[i + children - 1] - arr[i]
print(diff)


[m, n] = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr.sort()
enkck = arr[m - 1] - arr[0]
if n - m > 0:
	for i in range(1, n - m + 1):
		if arr[m] - arr[i] < enkck:
			enkck = arr[m] - arr[i]
		m += 1
	print(enkck)
else:
	print(enkck)


(n, m) = map(int, input().split())
inp = list(map(int, input().split()))
inp.sort()
(minimum, diff) = (100000, -1)
j = 0
for i in range(n - 1, m):
	diff = inp[i] - inp[j]
	j = j + 1
	minimum = min(diff, minimum)
print(minimum)


(n, m) = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
l.sort()
s = n
d = l[-1] - l[0]
for i in range(len(l) - s + 1):
	j = l[i:i + s]
	if d > j[-1] - j[0]:
		d = j[-1] - j[0]
print(d)


(a, b) = map(int, input().split())
t = []
m = []
n = input().split(' ')
for i in range(b):
	t.append(int(n[i]))
t.sort()
for i in range(b - a + 1):
	c = abs(t[i + a - 1] - t[i])
	m.append(c)
print(min(m))


(n, m) = [int(x) for x in input().split()]
pieces = [int(x) for x in input().split()]
stdpieces = sorted(pieces)
ans = float('inf')
for x in range(m - n + 1):
	ans = min(ans, stdpieces[x + n - 1] - stdpieces[x])
print(ans)


str = input().split()
(n, m) = (int(str[0]), int(str[1]))
puzzles = [int(puzzle) for puzzle in input().split()]
puzzles.sort()
min_difference = 10 ** 10
for i in range(m - n + 1):
	min_difference = min(min_difference, puzzles[i + n - 1] - puzzles[i])
print(min_difference)


(n, m) = map(int, input().split(' '))
mas = list(map(int, input().split(' ')))
mas.sort()
i = n - 1
min = 9999999999999999999
while i < m:
	if min > mas[i] - mas[i - n + 1]:
		min = mas[i] - mas[i - n + 1]
	i += 1
print(min)


(n, m) = map(int, input().split())
t = 1001
p = sorted(list(map(int, input().split())))
for i in range(m - n + 1):
	t = min(abs(p[i] - p[i + n - 1]), t)
print(t)


(n, m) = [int(x) for x in input().split()]
f = sorted([int(x) for x in input().split()])
diff = 9999
for i in range(m - n + 1):
	t = f[i:i + n]
	d = max(t) - min(t)
	if diff >= d:
		diff = d
print(diff)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
minimum = max(l) - min(l)
for i in range(k):
	temp = l[i:i + n]
	if max(temp) - min(temp) < minimum and len(temp) == n:
		minimum = max(temp) - min(temp)
print(minimum)


(n, m) = tuple(map(int, input().split(' ')))
no = list(map(int, input().split(' ')))
no.sort()
minj = 1000
min1 = 0
for i in range(m - n + 1):
	j = no[i + n - 1] - no[i]
	if j < minj:
		minj = j
		min1 = i
print(int(minj))


a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sorted(b)
x = int(0)
d = []
while x < a[1] - a[0] + 1:
	d.append(c[a[0] - 1 + x] - c[x])
	x = x + 1
print(min(d))


(n, m) = map(int, input().split())
a = [int(x) for x in input().split()]
a.sort()
final = []
for i in range(m - n + 1):
	c = a[i + n - 1] - a[i]
	final.append(c)
final.sort()
print(final[0])


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


(n, m) = [int(x) for x in input().split(' ')]
quantities = sorted([int(x) for x in input().split(' ')])
best = quantities[n - 1] - quantities[0]
for i in range(m - n + 1):
	if quantities[n + i - 1] - quantities[i] < best:
		best = quantities[n + i - 1] - quantities[i]
print(best)


def fun():
	numb = input()
	numb = numb.split(' ')
	n = int(numb[0])
	data = input()
	vec = []
	data = data.split(' ')
	for i in data:
		vec.append(int(i))
	vec.sort()
	res = vec[n - 1] - vec[0]
	for i in range(len(vec) - n + 1):
		cur = i + n - 1
		if vec[cur] - vec[i] < res:
			res = vec[cur] - vec[i]
	print(res)
fun()


z = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
t = 99999
for i in range(z[1] - z[0] + 1):
	for j in range(z[0]):
		qw = a[i + z[0] - 1] - a[i]
		if qw < t:
			t = qw
print(t)


def puzzles(n, array):
	array = sorted(array)
	diff = float('inf')
	for i in range(len(array)):
		if i + n <= len(array) and diff > array[i + n - 1] - array[i]:
			diff = array[i + n - 1] - array[i]
			a = i
			b = i - 1 + n
	print(array[b] - array[a])
(n, m) = input().split()
array = [int(x) for x in input().split()]
puzzles(int(n), array)


s = [int(i) for i in input().split(' ')]
n = s[0]
m = s[1]
b = []
a = [int(n) for n in input().split(' ')]
a = sorted(a)
for i in range(m - n + 1):
	b.append(a[i + n - 1] - a[i])
print(min(b))


n = input().split(' ')
students = int(n[0])
puzzles_total = int(n[1])
n = input().split(' ')
puzzles = []
for i in n:
	puzzles.append(int(i))
puzzles.sort()
min_diff = puzzles[puzzles_total - 1] - puzzles[0]
for i in range(puzzles_total):
	for j in range(i + students - 1, puzzles_total):
		diff = puzzles[j] - puzzles[i]
		if diff < min_diff:
			min_diff = diff
print(min_diff)


from sys import stdin
input = stdin.readline
nm = input().split()
n = int(nm[0])
m = int(nm[1])
a = list(map(int, input().rstrip().split()))
a.sort()
b = []
for _ in range(m - n + 1):
	b.append(a[_ + n - 1] - a[_])
print(min(b))


(a, b) = input().split()
a = int(a)
b = int(b)
x = [int(q) for q in input().split()]
y = sorted(x)
c = []
for i in range(b - a + 1):
	c.append(y[i + a - 1] - y[i])
print(min(c))


import math
from decimal import Decimal

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = map(int, input().split())
	return (n, m)

def dva():
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return (n, m, b)

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)

def ist(x):
	d = 1
	while d < x:
		d *= 2
	return d == x
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
mn = 1000000000000000000000000000000000
for i in range(m - n + 1):
	if a[i + n - 1] - a[i] < mn:
		mn = a[i + n - 1] - a[i]
print(mn)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
mn = 10000
for i in range(m - n + 1):
	for j in range(i, i + n):
		if j == i + n - 1:
			mn = min(mn, abs(l[i] - l[j]))
print(mn)


(n, m) = [int(c) for c in input().split()]
f = [int(c) for c in input().split()]
f.sort()
i = 0
j = n - 1
mind_abstand = max(f) + 1
while j < m:
	abstand = f[j] - f[i]
	if abstand < mind_abstand:
		mind_abstand = abstand
	i += 1
	j += 1
print(mind_abstand)


(n, m) = list(map(int, input().split()))
listgift = list(map(int, input().split()))
listgift.sort()
mindiff = 1000
for i in range(m - n + 1):
	B = listgift[i]
	A = listgift[i + n - 1]
	diff = A - B
	if diff < mindiff:
		mindiff = diff
print(mindiff)


import math
inp = list(input().split(' '))
(n, m) = (int(inp[0]), int(inp[1]))
inp = list(input().split(' '))
ls = []
for i in range(0, m):
	ls.append(int(inp[i]))
ans = math.inf
ls.sort()
for i in range(0, m - n + 1):
	ans = min(ls[i + n - 1] - ls[i], ans)
print(ans)


def inp(n):
	if n == 1:
		return map(int, stdin.readline().split())
	elif n == 2:
		return map(float, stdin.readline().split())
	else:
		return map(str, stdin.readline().split())

def arr_inp():
	return [int(x) for x in stdin.readline().split()]
from sys import stdin
(n, m) = inp(1)
a = sorted(arr_inp())
mi = float('inf')
for i in range(0, m - n + 1):
	mi = min(mi, a[n + i - 1] - a[i])
print(mi)


nm = list(map(int, input().split()))
n = nm[0]
m = nm[1]
l = list(map(int, input().split()))
l.sort()
i = 0
j = n - 1
result = 1000
while j < len(l):
	result = min(result, l[j] - l[i])
	i += 1
	j += 1
print(result)


def inplst():
	return list(map(int, input().split()))
(me, n) = map(int, input().split())
l = inplst()
l.sort()
r = 10001

def maxdiff(l):
	m = 0
	return max(l) - min(l)
ind = 0
while ind + me <= n:
	r = min(r, maxdiff(l[ind:ind + me]))
	ind += 1
print(r)


(n, m) = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
p.sort()
res = 10000000000000
for i in range(len(p) - n + 1):
	temp = p[i + n - 1] - p[i]
	if temp < res:
		res = temp
print(res)


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
arr = sorted(arr)
count = float('inf')
for i in range(0, m - n + 1):
	count = min(count, arr[i + n - 1] - arr[i])
if count == float('inf'):
	print(0)
else:
	print(count)


(m, n) = [int(x) for x in input().split()]
f = sorted(map(int, input().split()))
y = [f[k + m - 1] - f[k] for k in range(n - m + 1)]
y.sort()
print(y[0])


i = input('')
i = list(i.split())
n = int(i[0])
m = int(i[1])
l = input('')
l = list(l.split())
for i in range(len(l)):
	l[i] = int(l[i])
l.sort(reverse=True)
bigd = []
for i in range(len(l) - n + 1):
	k = l[i:i + n]
	maxboi = max(k)
	minboi = min(k)
	d = maxboi - minboi
	bigd.append(d)
print(min(bigd))


(n, m) = [int(i) for i in input().split()]
nums = sorted([int(i) for i in input().split()])
diffs = []
for i in range(m - n + 1):
	diffs.append(nums[i + n - 1] - nums[i])
print(min(diffs))


from sys import stdin, stdout
(n, m) = map(int, input().split())
arr = [int(x) for x in stdin.readline().split()]
arr.sort()
temp = 2345456
for k in range(0, m - n + 1):
	if temp > arr[k + n - 1] - arr[k]:
		temp = arr[k + n - 1] - arr[k]
if temp == 2345456:
	temp = 0
print(temp)


(n, m) = map(int, input().split())
puzzles = list(map(int, input().split()))
puzzles.sort()
min_diff = float('inf')
for i in range(0, m - n + 1):
	if puzzles[i + n - 1] - puzzles[i] < min_diff:
		min_diff = puzzles[i + n - 1] - puzzles[i]
print(min_diff)


(n, m) = map(int, input().split())
p = sorted(map(int, input().split()))
d = 100000000000000
for x in range(m - n + 1):
	p1 = p[x:x + n]
	if max(p1) - min(p1) < d:
		d = max(p1) - min(p1)
print(d)


def rearrangement(a):
	out = []
	z = len(a)
	for i in range(0, z):
		d = min(a)
		out.append(d)
		a.remove(d)
	return out
e = [int(x) for x in input().split()]
l = rearrangement([int(x) for x in input().split()])
f = []
for i in range(0, e[1] - e[0] + 1):
	f.append(l[i + e[0] - 1] - l[i])
print(min(f))


(n, m) = map(int, input().split())
lis = list(map(int, input().split()))
lis.sort()
check = 9999
for i in range(m - (n - 1)):
	diff = lis[i + n - 1] - lis[i]
	if check > diff:
		check = diff
print(check)


(n, m) = [int(x) for x in input().split(' ')]
f = sorted([int(x) for x in input().split(' ')])
ans = 10000
for (A, B) in zip(f, f[n - 1:]):
	ans = min(ans, B - A)
print(ans)


(n, m) = map(int, input().split())
x = list(map(int, input().split()))
y = sorted(x)
mix = abs(y[0] - y[0 + n - 1])
for a in range(len(x) - n + 1):
	if abs(y[a] - y[a + n - 1]) < mix:
		mix = abs(y[a] - y[a + n - 1])
print(mix)


(n, m) = map(int, input().split())
lst = list(map(int, input().split()))
lst.sort()
lst2 = lst[::-1]
i = 0
s = max(lst) - min(lst)
while i <= m - n:
	x = lst[i] - lst[i + n - 1]
	if x < 0:
		x = -x
	if x < s:
		s = x
	x = lst2[i] - lst2[i + n - 1]
	if x < 0:
		x = -x
	if x < s:
		s = x
	i += 1
print(s)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
min_ = float('inf')
for i in range(0, k - n + 1):
	if a[i + n - 1] - a[i] < min_:
		min_ = a[i + n - 1] - a[i]
print(min_)


nm = input().split()
n = int(nm[0])
m = int(nm[1])
a = list(map(int, input().rstrip().split()))
a.sort()
b = []
for _ in range(m - n + 1):
	b.append(a[_ + n - 1] - a[_])
print(min(b))


(n, m) = map(int, input().split())
a = [int(x) for x in input().split()]
a.sort()
ans = 1000000
for i in range(0, m - n + 1):
	if a[i + n - 1] - a[i] < ans:
		ans = a[i + n - 1] - a[i]
print(ans)


def input_numbers():
	return list(map(int, input().split()))
(n, m) = input_numbers()
f = input_numbers()
f.sort()
min_diff = f[n - 1] - f[0]
i = 1
while i <= m - n:
	diff = f[i + n - 1] - f[i]
	if diff < min_diff:
		min_diff = diff
	i += 1
print(min_diff)


(n, m) = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
l = sorted(l)
mn = 99999999
for i in range(len(l)):
	if i + n - 1 < m and l[i + n - 1] - l[i] < mn:
		mn = l[i + n - 1] - l[i]
print(mn)


nm = [int(i) for i in input().split(' ')]
n = nm[0]
m = nm[1]
lists = [int(i) for i in input().split(' ')]
lists.sort()
result = 0
for j in range(m - n + 1):
	if j == 0:
		result = lists[j + n - 1] - lists[j]
	elif lists[j + n - 1] - lists[j] <= result:
		result = lists[j + n - 1] - lists[j]
print(result)


a = input()
a = int(a[:a.find(' ')])
b = list(map(int, input().split()))
b.sort()
c = 0
d = []
while c <= len(b) - a:
	d.append(b[c + a - 1] - b[c])
	c += 1
d.sort()
print(d[0])


import sys
(n, m) = map(int, input().split())
f = list(map(int, input().split()))
f = sorted(f)
k = 1000
for i in range(m - n + 1):
	if k > f[i + n - 1] - f[i]:
		k = f[i + n - 1] - f[i]
print(k)


(n, m) = map(int, input().split(' '))
mas = list()
tmp = input().split(' ')
for item in tmp:
	mas.append(int(item))
mas.sort()
i = 0
res = 100000000
while i <= m - n:
	res = min(res, mas[i + n - 1] - mas[i])
	i += 1
print(res)


(n, m) = [int(x) for x in input().split()]
f = [int(x) for x in input().split()]
f.sort()
ans = 1000000
for i in range(m - n + 1):
	ans = min(ans, f[i + n - 1] - f[i])
print(ans)


(n, m) = map(int, input().split())
p = [k for k in map(int, input().split())]
for i in range(m):
	for j in range(m - 1, i, -1):
		if p[j] < p[j - 1]:
			temp = p[j]
			p[j] = p[j - 1]
			p[j - 1] = temp
sums = [0 for k in p]
for i in range(1, m):
	sums[i] = p[i] - p[i - 1] + sums[i - 1]
result = sum(sums)
for i in range(m - n + 1):
	result = min(result, sums[i + n - 1] - sums[i])
print(result)


(n, p) = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
c = []
for b in range(len(x) - n + 1):
	q = x[b + (n - 1)] - x[b]
	c.append(q)
print(min(c))


(n, m) = map(int, input().split())
lst = list(map(int, input().split()))
lst = sorted(lst)
lst1 = []
if m == n:
	lst1.append(max(lst) - min(lst))
else:
	for i in range(0, m - n + 1):
		lst1.append(lst[i + n - 1] - lst[i])
print(min(lst1))


(n, m) = [int(i) for i in input().split(' ')]
str_arr = input().split(' ')
arr = [int(num) for num in str_arr]
arr.sort()
q = arr[n - 1] - arr[0]
for i in range(m - n + 1):
	if i == 0:
		continue
	q = min(q, arr[n - 1 + i] - arr[i])
print(q)


n = list(map(int, input().split(' ')))
l = list(map(int, input().split(' ')))
l.sort()
i = 0
j = n[0] - 1
min = l[j] - l[i]
while j < n[1]:
	if l[j] - l[i] < min:
		min = l[j] - l[i]
	i += 1
	j += 1
print(min)


(n, m) = list(map(int, input().split()))
f = list(map(int, input().split()))
f.sort()
min_diff = max(f)
for (index, i) in enumerate(f):
	if index + n - 1 == m:
		break
	if f[index + n - 1] - i < min_diff:
		min_diff = f[index + n - 1] - i
print(min_diff)


nm = input().split(' ')
ps = input().split(' ')
p = list()
for i in ps:
	p.append(int(i))
p.sort()
mins = -1
for i in range(int(nm[1]) - int(nm[0]) + 1):
	m = p[i + int(nm[0]) - 1] - p[i]
	if m < mins or mins == -1:
		mins = m
if mins == -1:
	print(0)
else:
	print(mins)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
m = max(l[:n]) - min(l[:n])
for i in range(len(l) - n + 1):
	if max(l[i:i + n]) - min(l[i:i + n]) < m:
		m = max(l[i:i + n]) - min(l[i:i + n])
print(m)


def min_diff(n, m, arr):
	if m == n:
		return arr[-1] - arr[0]
	diff = []
	for i in range(0, len(arr) - n + 1):
		diff.append(arr[n + i - 1] - arr[i])
	return min(diff)
(n, m) = map(int, input().split())
arr = [int(v) for v in input().split()]
arr.sort()
print(min_diff(n, m, arr))


(n, m) = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr.sort()
minn = 10000
i = m - 1
while i >= n - 1:
	var = arr[i] - arr[i - n + 1]
	if minn > var:
		minn = var
	i -= 1
print(minn)


input1 = input().split()
n = int(input1[0])
m = int(input1[1])
f = input().split()
sequence = list(map(int, f))
sequence = sorted(sequence)
chazhi = sequence[n - 1] - sequence[0]
for j in range(m - n + 1):
	a = sequence[j + n - 1] - sequence[j]
	if a < chazhi:
		chazhi = a
print(chazhi)


(n, m) = map(int, input().split())
f = input().split()
a = []
b = []
for i in range(m):
	a.append(int(f[i]))
a.sort()
for i in range(m - n + 1):
	b.append(a[i + n - 1] - a[i])
print(min(b))


n = input().split()
n = [int(x) for x in n]
arr = input().split()
arr = [int(x) for x in arr]
arr.sort()
ans = max(arr)
for i in range(len(arr) - n[0] + 1):
	st = {arr[j] for j in range(i, i + n[0])}
	ans = ans if ans < max(st) - min(st) else max(st) - min(st)
print(ans)


(n, m) = [int(x) for x in input().split()]
f = [int(x) for x in input().split()]
f = sorted(f)
min = f[n - 1] - f[0]
for i in range(m - (n - 1)):
	q = f[i + (n - 1)] - f[i]
	if q <= min:
		min = q
print(min)


(n, m) = map(int, input().split())
mas = [int(i) for i in input().split()]
mas.sort()
min_delta = 100000000
for i in range(m - n + 1):
	if abs(mas[i] - mas[i + (n - 1)]) < min_delta:
		min_delta = abs(mas[i] - mas[i + (n - 1)])
print(min_delta)


(n, m) = map(int, input().split())
l = sorted(map(int, input().split()))
min = 1000
for i in range(0, m - n + 1):
	if l[i + n - 1] - l[i] < min:
		min = l[i + n - 1] - l[i]
print(min)


(n, m) = list(map(int, input().split()))[:]
list_in_int = list(map(int, input().split()))
sortedList = sorted(list_in_int)
diff = sortedList[n - 1] - sortedList[0]
sortedList.pop(0)
while len(sortedList) >= n:
	if sortedList[n - 1] - sortedList[0] < diff:
		diff = sortedList[n - 1] - sortedList[0]
	sortedList.pop(0)
print(diff)


import sys
import math
(n, m) = input().split()
a = [int(x) for x in input().split()]
a.sort()
ans = 10000
for i in range(len(a) - int(n) + 1):
	if a[i + int(n) - 1] - a[i] < ans:
		ans = a[i + int(n) - 1] - a[i]
print(ans)


(n, m) = map(int, input().split())
num = input().split()
y = sorted((int(i) for i in num))
answer = []
for i in range(m - n + 1):
	answer.append(y[i + n - 1] - y[i])
print(min(answer))


def read_int():
	return int(input())

def read_ints():
	return map(int, input().split(' '))
a = list(read_ints())
b = list(read_ints())
j = 0
mn = 999999
b.sort()
for i in range(a[0] - 1, a[1]):
	mn = min(b[i] - b[j], mn)
	j += 1
print(mn)


(n, m) = map(int, input().split())
f = sorted(map(int, input().split()))
x = 0
a = [0] * (m - n + 1)
while x + n - 1 < m:
	a[x] = f[x + n - 1] - f[x]
	x += 1
print(min(a))


f = lambda : map(int, input().split())
(n, m) = f()
fm = sorted(f())
print(min([fm[i + n - 1] - fm[i] for i in range(m - n + 1)]))


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


def solve(n, l):
	window = n - 1
	l.sort()
	min_diff = 1000
	for i in range(len(l) - window):
		diff = l[i + window] - l[i]
		min_diff = min(min_diff, diff)
	return min_diff

def test():
	l = [int(x) for x in '10 12 10 7 5 22'.split()]
	assert solve(4, l) == 5
	import sys
	sys.exit(0)
(n, m) = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
print(solve(n, l))


def main():
	(n, m) = map(int, sys.stdin.readline().split())
	sizes = list(map(int, sys.stdin.readline().split()))
	sizes.sort()
	best = inf
	for i in range(m - n + 1):
		best = min(best, sizes[i + n - 1] - sizes[i])
	sys.stdout.write(str(best))
import sys
from math import inf
main()


(a, b) = map(int, input().split())
lis = [int(x) for x in input().split()]
lis1 = sorted(lis)
lisr = []
for i in range(b - a + 1):
	lisr.append(max(lis1[i:i + a]) - min(lis1[i:i + a]))
print(min(lisr))


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


(n, m) = input().split()
num = sorted([int(x) for x in input().split()])
ans = num[int(m) - 1] - num[0]
for i in range(int(m) - int(n) + 1):
	ans = min(ans, num[i + int(n) - 1] - num[i])
print(ans)


def sub(x):
	x.sort()
	y = x[-1] - x[0]
	return y
wew = input().split()
n = int(wew[0])
m = int(wew[1])
MY_LIST = list(map(int, input().split()))
MY_LIST.sort()
WHOLE = []
for a in range(m - n + 1):
	WHOLE.append(MY_LIST[a:a + n])
NEW_WHOLE = list(map(sub, WHOLE))
print(min(NEW_WHOLE))


(n, m) = input().split()
(n, m) = (int(n), int(m))
lst = input().split()
mini = None
for i in range(m):
	lst[i] = int(lst[i])
lst.sort()
for i in range(m - n + 1):
	temp = lst[i + n - 1] - lst[i]
	if temp >= 0:
		if mini == None:
			mini = temp
		elif temp < mini:
			mini = temp
print(mini)


(n, m) = list(map(int, input().split()))
f = list(map(int, input().split()))
f.sort()
d_min = 1000
for i in range(m - n + 1):
	s = f[i + n - 1] - f[i]
	if s < d_min:
		d_min = s
print(d_min)


from math import inf

def solve(n, m, f):
	f.sort()
	d = inf
	for i in range(m - n + 1):
		d = min(d, f[i + n - 1] - f[i])
	return d

def main():
	(n, m) = list(map(int, input().split()))
	f = list(map(int, input().split()))
	print(solve(n, m, f))
main()


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


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


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
arr = sorted(arr)
result = 1001
for i in range(n - 1, m):
	if arr[i] - arr[i - (n - 1)] < result and arr[i] - arr[i - (n - 1)] >= 0:
		result = arr[i] - arr[i - (n - 1)]
print(result)


_author__ = 'CrunchyTortoise'
(n, m) = [int(x) for x in input().split()]
s = [int(x) for x in input().split()]
s.sort()
res = 9999999999
for x in range(m - (n - 1)):
	res = min(res, s[x + n - 1] - s[x])
print(res)


(n, m) = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
B = []
for i in range(m - (n - 1)):
	B.append(A[i] - A[i + n - 1])
print(min(B))


arr = lambda : map(int, input().split())
(n, m) = arr()
sort = sorted(arr())
print(min([sort[n + i - 1] - sort[i] for i in range(m - n + 1)]))


(n, m) = map(int, input().split())
f = sorted([int(i) for i in input().split(' ')])
if m > n:
	ans = 9999999999
	for i in range(0, len(f) - n + 1):
		num = max(f[i:i + n]) - min(f[i:i + n])
		if num <= ans:
			ans = num
elif n == m:
	ans = max(f) - min(f)
print(ans)


(n, m) = map(int, input().split())
pieces = map(int, input().split())

def solve(n, m, p):
	p = sorted(p)
	i = n - 1
	j = 0
	dif = 1001
	while i < m:
		dif = min(dif, p[i] - p[j])
		i += 1
		j += 1
	return dif
print(solve(n, m, pieces))


def puzzles(lst, n, m):
	minimum = 1000 * 1000 * 1000
	for i in range(m - n + 1):
		minimum = min(minimum, lst[i + n - 1] - lst[i])
	if n == m:
		return lst[m - 1] - lst[0]
	return minimum
(N, M) = [int(j) for j in input().split()]
b = [int(x) for x in input().split()]
print(puzzles(sorted(b), N, M))


a = input()
a = a.split()
a = [int(x) for x in a]
b = input()
b = b.split()
b = [int(x) for x in b]
b = sorted(b)
end = a[1] - a[0] + 1
m = b[-1] - b[0]
for i in range(0, end):
	temp = b[a[0] + i - 1] - b[i]
	if temp < m:
		m = temp
print(m)


(n, m) = [int(x) for x in input().split()]
nums = sorted([int(x) for x in input().split()])
res = float('inf')
for i in range(m - n + 1):
	res = min(res, nums[i + n - 1] - nums[i])
print(res)


d = int(input().split()[0])
ms = [int(i) for i in input().split()]
ms.sort()
min = ms[d - 1] - ms[0]
for x in range(len(ms) - (d - 1)):
	nm = ms[x:x + d]
	if nm[-1] - nm[0] < min:
		min = nm[-1] - nm[0]
print(min)


(m, n) = map(int, input().strip().split(' '))
s = list(map(int, input().strip().split(' ')))
s = sorted(s)
m_in = 1000
for i in range(len(s) - m + 1):
	if s[i + m - 1] - s[i] < m_in:
		m_in = s[i + m - 1] - s[i]
print(m_in)


from itertools import islice
(required_puzzles, shop_puzzle_nums) = [int(x) for x in input().split(' ')]

def window(seq, n=2):
	it = iter(seq)
	result = tuple(islice(it, n))
	if len(result) == n:
		yield result
	for elem in it:
		result = result[1:] + (elem,)
		yield result
available_puzzles = sorted([int(x) for x in input().split(' ')])
min_diff = 99999
for win in window(available_puzzles, required_puzzles):
	if win[len(win) - 1] - win[0] < min_diff:
		min_diff = win[len(win) - 1] - win[0]
print(min_diff)


(n, k) = map(int, input().split())
L = [int(x) for x in input().split()]
L1 = sorted(L)
a0 = L1[n - 1] - L1[0]
for i in range(k - n + 1):
	a = L1[n + i - 1] - L1[i]
	a0 = min(a, a0)
print(a0)


z = list(map(int, input().split()))
x = list(map(int, input().split()))
x = sorted(x)
c = []
for i in range(z[1] - z[0] + 1):
	c.append(x[i + z[0] - 1] - x[i])
print(min(c))


(a, n) = map(int, input().split())
N = [int(num) for num in input().split(' ', n - 1)]
i = t = 0
m = sum(N)
N.sort()
while i <= n - a:
	t = N[i + a - 1] - N[i]
	m = min(m, t)
	i += 1
print(m)


(n, m) = list(map(int, input().split()))[:]
ilist = list(map(int, input().split()))
sortd = sorted(ilist)
diff = sortd[n - 1] - sortd[0]
while len(sortd) >= n:
	if sortd[n - 1] - sortd[0] < diff:
		diff = sortd[n - 1] - sortd[0]
	sortd.pop(0)
print(diff)


(n, m) = map(int, input().split(' '))
l = sorted(list(map(int, input().split(' '))))
minm = l[m - 1] - l[0]
t = m - n + 1
for i in range(t):
	minm = min(minm, l[n - 1 + i] - l[i])
print(minm)


line_one = ''
line_two = ''
line_one += input()
line_two += input()
line_one = line_one.split(' ')
line_two = line_two.split(' ')
array = []
for i in range(0, int(line_one[1])):
	array.append(int(line_two[i]))
array.sort()
minv = array[int(line_one[0]) - 1] - array[0]
for i in range(int(line_one[1])):
	if i + int(line_one[0]) - 1 < int(line_one[1]):
		if array[i + int(line_one[0]) - 1] - array[i] < minv:
			minv = array[i + int(line_one[0]) - 1] - array[i]
print(minv)


(n, m) = map(int, input().split())
ls1 = [int(x) for x in input().split()]
ls2 = []
ls1.sort()
for i in range(len(ls1) - n + 1):
	mi = max(ls1[i:i + n:1]) - min(ls1[i:i + n:1])
	ls2.append(mi)
print(min(ls2))


(k, n) = map(int, input().split())
sp = list(map(int, input().split()))
sp.sort()
mx = 10001
for i in range(n - k + 1):
	t = max(sp[i:i + k]) - min(sp[i:i + k])
	if mx > t:
		mx = t
print(mx)


(n, m) = map(int, input().split())
s = input().split()[:m]
s = [int(s[i]) for i in range(m)]
s.sort()
d = []
j = n
for i in range(m):
	k = s[i:n]
	if len(k) >= j:
		k.sort()
		diff = int(k[-1]) - int(k[0])
		d.append(diff)
	n += 1
print(min(d))


(x, y) = map(int, input().split())
p = sorted(list(map(int, input().split())))
x -= 1
ma = max(p)
for i in range(y - x):
	ma = min(ma, p[i + x] - p[i])
print(ma)


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
l = sorted(f)
i = 0
b = max(l)
while i <= m - n:
	a = l[i + n - 1] - l[i]
	if a < b:
		b = a
	i = i + 1
print(b)


(students, puzzles) = list(map(int, input().split()))
arr = sorted(list(map(int, input().split())))
lowest = max(arr[:students]) - min(arr[:students])
for i in range(0, puzzles - students + 1):
	temp = arr[i:i + students]
	current = max(temp) - min(temp)
	if current < lowest:
		lowest = current
print(lowest)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
i = 0
e = n
y = 999999999
while e <= m:
	j = i
	k = j + 1
	f = n + i
	while f <= m:
		a = []
		a = l[k:f]
		a.append(l[j])
		a.sort()
		x = max(a) - min(a)
		if x < y:
			y = x
		k = k + 1
		f = f + 1
	i = i + 1
	e = e + 1
print(y)


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


(n, m) = map(int, input().split())
number = [int(x) for x in input().split()]
number.sort()
differences = []
for i in range(len(number) - n + 1):
	diff = max(number[i:i + n]) - min(number[i:i + n])
	differences.append(diff)
print(min(differences))


def solve():
	num_students = int(input().split(' ')[0])
	puzzles = list(map(int, input().split(' ')))
	puzzles.sort()
	i = 0
	least_diff = None
	while i + num_students <= len(puzzles):
		diff = abs(max(puzzles[i:i + num_students]) - min(puzzles[i:i + num_students]))
		if least_diff is None or diff < least_diff:
			least_diff = diff
		if least_diff == 0:
			return 0
		i += 1
	return least_diff
print(solve())


(n, m) = [int(string) for string in input().split()]
f = [int(string) for string in input().split()]
f.sort()
delta = 1000
for i in range(0, m - n + 1):
	delta = min(delta, f[i + n - 1] - f[i])
print(delta)


[m, n] = list(map(int, input().split()))
arr = list(map(int, input().split()))
me = 10000
i = 0
arr.sort()
while i + m - 1 < n:
	if arr[i + m - 1] - arr[i] < me:
		me = min(me, arr[i + m - 1] - arr[i])
	i += 1
print(me, end='')


s = input()
(n, m) = tuple(map(int, s.split(' ')))
s = input()
min = 1000
f = tuple(map(int, s.split(' ')))
f = sorted(f)
min = 1000
for i in range(m - n + 1):
	if min > f[i + n - 1] - f[i]:
		min = f[i + n - 1] - f[i]
print(min)


def calc(n, m, f):
	f = sorted(f)
	best = float('inf')
	for i in range(n - 1, len(f)):
		best = min(best, f[i] - f[i - n + 1])
	return best
(n, m) = map(int, input().split())
f = list(map(int, input().split()))
print(calc(n, m, f))


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


(n, m) = [int(x) for x in input().split()]
s = [int(x) for x in input().split()]
s.sort()
x = s[n - 1] - s[0]
for i in range(1, m - n + 1):
	x = min(x, s[n + i - 1] - s[i])
print(x)


(n, m) = [int(x) for x in input().split()]
f = sorted([int(x) for x in input().split()])
out = max(f) + 1
for i in range(m - n + 1):
	out = min(out, f[n + i - 1] - f[i])
print(out)


ar = []
for i in input().split(' '):
	ar.append(int(i))
pazzle = []
for i in input().split(' '):
	pazzle.append(int(i))
pazzle.sort()
ch = 0
curr = 0
for i in range(ar[0] - 1, ar[1]):
	if ch != 0:
		if curr > pazzle[i] - pazzle[i - ar[0] + 1]:
			curr = pazzle[i] - pazzle[i - ar[0] + 1]
	else:
		curr = pazzle[i] - pazzle[i - ar[0] + 1]
		ch = 1
print(curr)


import sys
(n, m) = map(int, sys.stdin.readline().split())
alist = sorted(list(map(int, sys.stdin.readline().split())))
ans = alist[n - 1] - alist[0]
for i in range(1, m - n + 1):
	if ans > alist[i + n - 1] - alist[i]:
		ans = alist[i + n - 1] - alist[i]
print(ans)


list = input().split(' ')
list2 = input().split(' ')
for i in range(2):
	list[i] = int(list[i])
for i in range(len(list2)):
	list2[i] = int(list2[i])
list2.sort(reverse=True)
min = 1000
for i in range(list[1] - list[0] + 1):
	if list2[i] - list2[i + list[0] - 1] < min:
		min = list2[i] - list2[i + list[0] - 1]
print(min)


(n, m) = [int(x) for x in input().split()]
pazzles = sorted([int(x) for x in input().split()])
diff = pazzles[n - 1] - pazzles[0]
for i in range(n, m):
	diff = min(diff, pazzles[i] - pazzles[i - n + 1])
print(diff)


def convert(arr):
	ans = []
	for i in arr:
		ans.append(int(i))
	return ans
inp = convert(input().split())
arr = convert(input().split())
arr.sort()
ans = 100000000
for i in range(inp[1] - inp[0] + 1):
	ans = min(ans, arr[i + inp[0] - 1] - arr[i])
print(ans)


(n, m) = list(map(int, input().split()))
f = list(map(int, input().split()))
f.sort()
(a, b) = (0, n - 1)
min = 6000000
if m == 2:
	print(f[1] - f[0])
else:
	j = m - n + 1
	for _ in range(j):
		if f[b] - f[a] < min:
			min = f[b] - f[a]
		a += 1
		b += 1
	print(min)


(n, m) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
A.sort()
ans = 1488228228
for i in range(len(A) - n + 1):
	ans = min(A[i + n - 1] - A[i], ans)
print(ans)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase
from fractions import *

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
(k, n) = value()
a = sorted(array())
ans = a[k - 1] - a[0]
for i in range(k, n):
	ans = min(ans, a[i] - a[i - k + 1])
print(ans)


from sys import stdin

def main():
	(n, m) = [int(i) for i in stdin.readline().strip().split()]
	cad = [int(x) for x in stdin.readline().strip().split()]
	cad.sort()
	vacia = []
	for k in range(m - (n - 1)):
		vacia.append(abs(cad[k] - cad[k + (n - 1)]))
	print(min(vacia))
main()


x = input()
(n, m) = (int(x.split()[0]), int(x.split()[1]))
puzzles = input()
f = []
for i in range(m):
	f.append(int(puzzles.split()[i]))
f.sort()
min = f[n - 1] - f[0]
if m > n:
	for i in range(0, m - n + 1):
		if f[i + n - 1] - f[i] < min:
			min = f[i + n - 1] - f[i]
print(min)


list1 = input().split()
prices = input().split()
n = int(list1[0])
m = int(list1[1])
for i in range(m):
	prices[i] = int(prices[i])
prices.sort()
minprice = prices[m - 1] - prices[0]
for j in range(m - n + 1):
	minprice = min(minprice, prices[j + n - 1] - prices[j])
print(minprice)


(n, m) = map(int, input().split())
a = sorted([int(_) for _ in input().split()])
t = a[n - 1] - a[0]
for i in range(m - n + 1):
	t = min(t, a[i + n - 1] - a[i])
print(t)


(a, b) = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
c = list(sorted(c))
mini = 100000000
for i in range(b - a + 1):
	if abs(c[i] - c[i + a - 1]) < mini:
		mini = abs(c[i] - c[i + a - 1])
print(mini)


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


(n, m) = list(map(int, input().split()))
puz = list(map(int, input().split()))
puz.sort()
if n == m:
	print(puz[-1] - puz[0])
	exit(0)
min_diff = puz[-1] - puz[0]
for i in range(m - n + 1):
	min_diff = min(min_diff, puz[n + i - 1] - puz[i])
print(min_diff)
exit(0)


(n, m) = map(int, input().split())
a = [int(i) for i in input().split()]
for i in range(m):
	for j in range(m - i - 1):
		if a[j] > a[j + 1]:
			(a[j], a[j + 1]) = (a[j + 1], a[j])
s = 100000000000000
for i in range(m - n + 1):
	s = a[i + n - 1] - a[i] if a[i + n - 1] - a[i] < s else s
print(s)


from sys import stdin, maxsize
(lines, line_index) = (stdin.readlines(), -1)

def get_line():
	global lines, line_index
	line_index += 1
	return lines[line_index]

def main():
	(n, m) = [int(x) for x in get_line().split()]
	d = sorted([int(x) for x in get_line().split()])
	diff = abs(d[0] - d[n - 1])
	(i, j) = (1, n)
	while i < m and j < m:
		tdiff = abs(d[i] - d[j])
		if tdiff < diff:
			diff = tdiff
		i += 1
		j += 1
	print(diff)
main()


(n, m) = [int(x) for x in input().split()]
f = [0] * m
f = [int(x) for x in input().split()]
f.sort()
least = f[n - 1] - f[0]
for i in range(0, m - n + 1):
	least = min(least, f[i + n - 1] - f[i])
print(least)


(n, m) = [int(i) for i in input().split()]
s = [int(i) for i in input().split()]
s.sort()
mi = s[-1] - s[0]
i = 0
j = n - 1
while j <= m - 1:
	p = s[i]
	q = s[j]
	t = q - p
	if t < mi:
		mi = t
	i = i + 1
	j = j + 1
print(mi)


(n, m) = [int(x) for x in input().split()]
li_ = sorted([int(x) for x in input().split()])
li = []
for i in range(m - n + 1):
	li += [li_[i + n - 1] - li_[i]]
print(min(li))


a = list((int(x) for x in input().split()))
(n, m) = (a[0], a[1])
d = []
b = list((int(x) for x in input().split()))
b = sorted(b)
for i in range(m - n + 1):
	f = b[i + n - 1] - b[i]
	d.append(f)
d = sorted(d)
print(d[0])


arr = list(map(int, input().split()))
n = arr[0]
m = arr[1]
arr = list(map(int, input().split()))
arr.sort()
mins = []
i = 0
c = m - n + 1
n -= 1
while c > 0:
	c -= 1
	mins.append(arr[n + i] - arr[i])
	i += 1
print(min(mins))


(num_children, num_puzzles) = map(int, input().split())
puzzles = list(map(int, input().split()))
puzzles.sort()
solution = puzzles[num_children - 1] - puzzles[0]
for puzzle_pos in range(1, num_puzzles - num_children + 1):
	solution = min(solution, puzzles[puzzle_pos + num_children - 1] - puzzles[puzzle_pos])
print(solution)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
m_n = 1000
for i in range(m - n + 1):
	m_n = min(m_n, max(l[i:i + n]) - min(l[i:i + n]))
	if m_n == 0:
		break
print(m_n)


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


from sys import stdin
(n, m) = (int(x) for x in stdin.readline().strip().split(' '))
f = list((int(x) for x in stdin.readline().strip().split(' ')))
f.sort()
result = 1000
for i in range(m - n + 1):
	a = f[i + n - 1] - f[i]
	if result > a:
		result = a
print(result)


(students, test) = input().split()
arr = input().split()
arr = list(map(int, arr))
arr.sort()
smallest = 10000000
for i in range(len(arr) - int(students) + 1):
	if -arr[i] + arr[i + int(students) - 1] < smallest:
		smallest = -arr[i] + arr[i + int(students) - 1]
print(smallest)


(N, M) = input().split()
(n, m) = (int(N), int(M))
list = [int(x) for x in input().split()]
list.sort()
i = 0
min = 10000

def check(i, n):
	a = list[i + n - 1] - list[i]
	return a
while i <= len(list) - n:
	a = check(i, n)
	if a < min:
		min = a
	i = i + 1
print(min)


(n, m) = [int(x) for x in input().split()]
f = sorted([int(x) for x in input().split()])
mi = 10000
for i in range(m - n + 1):
	mi = min(mi, f[i + n - 1] - f[i])
print(mi)


(n, m) = map(int, input().split())
arr = list(sorted(map(int, input().split())))
ans = arr[n - 1] - arr[0]
for i in range(1, m - n + 1):
	ans = min(ans, arr[i + n - 1] - arr[i])
print(ans)


(s, b) = [int(x) for x in input().split()]
d = [int(j) for j in input().split()]
f = []
k = []
for i in range(b):
	f.append(d[i])
z = sorted(f)
for i in range(s, b + 1):
	k.append(z[i - 1] - z[i - s])
print(min(k))


x = input()
y = x.split()
n = int(y[0])
m = int(y[1])
a = input()
b = a.split()
c = [int(d) for d in b]
c.sort()
l = [c[n - 1] - c[0]]
for i in range(0, m - n + 1):
	l.append(c[n + i - 1] - c[i])
print(min(l))


import math
(n, m) = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
arr.sort()
mindiff = math.inf
for i in range(m - n + 1):
	diff = arr[i + n - 1] - arr[i]
	if diff < mindiff:
		mindiff = diff
print(mindiff)


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


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


am = input().split()
pz = [int(i) for i in input().split()]
pz.sort()
dis = []
f = 0
l = int(am[0]) - 1
while l < len(pz):
	difference = pz[l] - pz[f]
	dis.append(difference)
	f += 1
	l += 1
print(min(dis))


(n, m) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.sort()
i = 0
diff = 1000
while i + n - 1 <= len(a) - 1:
	if a[i + n - 1] - a[i] < diff:
		diff = a[i + n - 1] - a[i]
	else:
		pass
	i += 1
print(diff)


(n, m) = [int(x) for x in input().split()]
pzz = [int(y) for y in input().split()]
pzz.sort()
a = pzz[n - 1] - pzz[0]
for i in range(1, m - n + 1):
	if pzz[i + n - 1] - pzz[i] < a:
		a = pzz[i + n - 1] - pzz[i]
print(a)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
minx = 99999999
for i in range(m - n + 1):
	minx = min(minx, a[i + n - 1] - a[i])
print(minx)


(n, m) = [int(i) for i in input().split()]
puzzle = [int(i) for i in input().split()]
puzzle.sort()
diff = puzzle[n - 1] - puzzle[0]
for i in range(1, m - n + 1):
	diff = min(diff, puzzle[i + n - 1] - puzzle[i])
print(diff)


(a, b) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
c = 0
min = float('inf')
for i in range(b - a + 1):
	if l[a - 1 + i] - l[i] < min:
		c = l[a - 1 + i] - l[i]
		min = c
print(c)


def solve(l, n, m):
	sl = sorted(l)
	return min([sl[i + n - 1] - sl[i] for i in range(m - n + 1)])
import random

def test():
	assert solve([9, 2], 2, 2) == 7
	assert solve([4, 4], 2, 2) == 0
	assert solve([9, 2, 4, 4], 2, 4) == 0
	assert solve([10, 12, 10, 7, 5, 22], 4, 6) == 5
	assert solve([1, 5, 2, 19], 2, 4) == 1
	print('test passes')
(n, m) = list(map(int, input().split()))
l = list(map(int, input().split()))
print(solve(l, n, m))


(n, m) = map(int, input().split())
r = [int(s) for s in input().split()]
r.sort()
R = []
for i in range(m - n + 1):
	R.append(r[i + n - 1] - r[i])
print(min(R))


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
f.sort()
mini = 1000
if m == n:
	print(max(f) - min(f))
else:
	for i in range(0, m - n + 1):
		if f[i + n - 1] - f[i] < mini:
			mini = f[i + n - 1] - f[i]
	print(mini)


firstLine = input()
values = firstLine.split(' ')
n = int(values[0])
m = int(values[1])
secondline = input()
numbers = [int(x) for x in secondline.split(' ')]
numbers.sort(reverse=True)
min = 1001
foundMin = False
for i in range(m - n + 1):
	if numbers[i] - numbers[i + n - 1] < min:
		min = numbers[i] - numbers[i + n - 1]
		foundMin = True
if foundMin:
	print(min)
else:
	print(numbers[0] - numbers[-1])


(n, m) = input().split()
n = int(n)
m = int(m)
puzzles = input().split()
for i in range(m):
	puzzles[i] = int(puzzles[i])
ordered = []
for i in range(m):
	ordered.append(max(puzzles))
	puzzles.remove(max(puzzles))
minimum = 0
for j in range(m - n + 1):
	count = ordered[j] - ordered[j + n - 1]
	if j == 0:
		minimum = count
	elif count < minimum:
		minimum = count
print(minimum)


a = [int(x) for x in input().split()]
f = [int(x) for x in input().split()]
f.sort()
n = a[0]
m = a[1]
diff = max(f) - min(f)
for i in range(m - n + 1):
	if diff > max(f[i:i + n]) - min(f[i:i + n]):
		diff = max(f[i:i + n]) - min(f[i:i + n])
print(diff)


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


(n, m) = [int(a) for a in input().split()]
puzzles = [int(b) for b in input().split()]
puzzles.sort()
Min = max(puzzles)
for x in range(0, m - n + 1):
	if max(puzzles[x:x + n]) - min(puzzles[x:x + n]) < Min:
		Min = max(puzzles[x:x + n]) - min(puzzles[x:x + n])
print(Min)


x = input().split()
x = [int(j) for j in x]
nr = input().split()
nr = [int(j) for j in nr]
nr = sorted(nr)
n = x[0] - 1
m = x[1]
sol = 9999
for i in range(m - n):
	if nr[i + n] - nr[i] < sol:
		sol = nr[i + n] - nr[i]
print(sol)


M_N_str = input()
M_N_arr = M_N_str.split(' ')
N = int(M_N_arr[0])
M = int(M_N_arr[1])
piece_str = input()
piece_arr = piece_str.split(' ')
piece_arr = [int(x) for x in piece_arr]
piece_arr.sort()
curr_min = 1000000001
for i in range(0, M - N + 1):
	if piece_arr[i + N - 1] - piece_arr[i] < curr_min:
		curr_min = piece_arr[i + N - 1] - piece_arr[i]
print(curr_min)


num_li = list(map(int, input().split()))
puz_li = list(map(int, input().split()))
puz_li.sort()
small_li = puz_li[:-num_li[0] + 1]
big_li = puz_li[num_li[0] - 1:]
i = 0
li = []
while i < len(big_li):
	li.append(big_li[i] - small_li[i])
	i = i + 1
print(min(li))


import pdb

def main():
	(n, m) = input().split(' ')
	n = int(n)
	m = int(m)
	values = input().split(' ')
	values = list(map(int, values))
	values.sort()
	loop_end = len(values) - n + 1
	i = 0
	max = 9000000
	while i < loop_end:
		result = findDifference(values[i:i + n])
		if result < max:
			max = result
		i += 1
	if max == 9000000:
		max = 0
	print(max)

def findDifference(array):
	return array[len(array) - 1] - array[0]
main()


(n, m) = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
c.sort()
minc = -1
lst0 = []
for x in range(m - n + 1):
	for y in range(n):
		lst0.append(c[y])
	if minc > max(lst0) - min(lst0) or minc == -1:
		minc = max(lst0) - min(lst0)
	lst0 = []
	c.remove(c[0])
print(minc)


(n, m) = map(int, input().split())
f = sorted(list(map(int, input().split())))
res = [0 for i in range(m - n + 1)]
for i in range(m - n + 1):
	res[i] = max(f[i:i + n]) - min(f[i:i + n])
print(min(res))


(n, m) = map(int, input().split())
x = list(map(int, input().split()))
x = sorted(x)
best = 10000000000000000000000000000000
for i in range(m - n + 1):
	if x[i + n - 1] - x[i] < best:
		best = x[i + n - 1] - x[i]
print(best)


(n, m) = map(int, input().split())
array = list(map(int, input().split()))
array.sort()
mi = 99999999999999999
for i in range(n - 1, m):
	if array[i] - array[i - n + 1] < mi:
		mi = array[i] - array[i - n + 1]
print(mi)


(n, m) = [int(x) for x in input().split()]
a = sorted([int(x) for x in input().split()])
minimum = 1001
for i in range(m - 1):
	temp = a[i:i + n]
	if len(temp) == n:
		if max(temp) - min(temp) < minimum:
			minimum = max(temp) - min(temp)
		elif max(temp) - min(temp) == 0:
			minimum = 0
			break
print(minimum)


(n1, m1) = input().split()
n = int(n1)
m = int(m1)
s = input().split()
s.sort(key=int, reverse=False)
p = 0
C = 1000000000000
while p <= m - n:
	c = int(s[n - 1 + p]) - int(s[p])
	if c < C:
		C = c
	p = p + 1
print(C)


import re
(n, m) = [int(i) for i in input().split()]
f = input() + ' '
f = [int(i) for i in re.findall('\\d+\\s', f)]
f.sort()
dif = f[n - 1] - f[0]
for i in range(1, m - n + 1):
	a = f[i + n - 1] - f[i]
	if dif > a:
		dif = a
print(dif)


(a, b) = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
c.sort()
x = c[a - 1] - c[0]
for i in range(b - a + 1):
	x = min(x, c[i + a - 1] - c[i])
print(x)


(m, n) = map(int, input().split())
A = list(map(int, input().split()))
for i in range(len(A) - 1):
	for j in range(len(A) - 1 - i):
		if A[j] > A[j + 1]:
			(A[j], A[j + 1]) = (A[j + 1], A[j])
s = A[len(A) - 1] - A[0]
for i in range(len(A) - m + 1):
	if s > A[i + m - 1] - A[i]:
		s = A[i + m - 1] - A[i]
print(s)


from sys import stdin, stdout
import bisect
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
from collections import Counter
import collections
import math
import heapq
import re

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def most_frequent(list):
	return max(set(list), key=list.count)

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def Convert(string):
	li = list(string.split(''))
	return li

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
prime = []
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j

def main():
	(n, m) = map(int, input().split())
	a = ain()
	a.sort()
	temp = a[n - 1] - a[0]
	k = n - 1
	for i in range(m - n + 1):
		temp1 = temp
		temp = min(a[i + k] - a[i], temp1)
	print(temp)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, m) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
import math
import sys
r = sys.maxsize
for i in range(m - n + 1):
	ncha = a[i + n - 1] - a[i]
	if ncha < r:
		r = ncha
print(r)


(n, m) = map(int, input().split())
arr = []
arr = list(map(int, input().split()))
arr.sort()
if m == n:
	print(arr[m - 1] - arr[0])
else:
	min_index = 0
	min_len = 1010
	for i in range(m - n + 1):
		if arr[i + n - 1] - arr[i] < min_len:
			min_len = arr[i + n - 1] - arr[i]
			min_index = i
	print(min_len)


(n, m) = [int(x) for x in input().split()]
f = [int(x) for x in input().split()]
f.sort()
mini = 1000
for i in range(m):
	if i + n - 1 == m:
		break
	if f[i + n - 1] - f[i] < mini:
		mini = f[i + n - 1] - f[i]
print(mini)


(n, m) = map(int, input().split())
f = input().split()
x = []
for i in range(len(f)):
	x += [int(f[i])]
x.sort()
a = []
for k in range(m - n + 1):
	a += [x[k + n - 1] - x[k]]
print(min(a))


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


(n, m) = map(int, input().split())
a = [int(x) for x in input().split()]
a = sorted(a)
ans = 999999
for i in range(0, len(a) - n + 1):
	ans = min(a[i + n - 1] - a[i], ans)
print(ans)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(0, m - 1):
	for j in range(i + 1, m):
		if a[i] > a[j]:
			tmp = a[i]
			a[i] = a[j]
			a[j] = tmp
min = 9999999999
for i in range(0, m - n + 1):
	thisDifference = a[i + n - 1] - a[i]
	if thisDifference < min:
		min = thisDifference
print(min)


(n, k) = map(int, input().split())
x = [int(i) for i in input().split()]
x.sort()
check = False
ans = float('inf')
for i in range(len(x) - n + 1):
	ans = min(ans, x[i + n - 1] - x[i])
	check = True
if check:
	print(ans)
else:
	print(0)


(n, m) = map(int, input().split())
a = [int(x) for x in input().split()]
b = a.sort()
k = max(a) - min(a)
for i in range(m - n + 1):
	if a[i + (n - 1)] - a[i] < k:
		k = a[i + (n - 1)] - a[i]
print(k)


x = [int(i) for i in list(input().split())]
y = [int(i) for i in list(input().split())]
y = sorted(y)
t = 1000000
for i in range(x[1] - x[0] + 1):
	if y[i + x[0] - 1] - y[i] < t:
		t = y[i + x[0] - 1] - y[i]
print(t)


(n, m) = map(int, input().split())
li = list(map(int, input().split()))
li.sort()
ans = 10000
for i in range(n - 1, m):
	ans = min(ans, li[i] - li[i - (n - 1)])
print(ans)


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


(n, m) = map(int, input().split())
nums = list(map(int, input().split()))
nums = sorted(nums)
minn = 10000
for i in range(n - 1, m):
	if nums[i] - nums[i - n + 1] < minn:
		minn = nums[i] - nums[i - n + 1]
print(minn)


import sys
input = sys.stdin.readline

def int_array():
	return list(map(int, input().split()))
(stu, n) = int_array()
stu -= 1
puzz = int_array()
puzz.sort()
a = 10000000.0
for i in range(n):
	mini = None
	maxi = None
	if i + stu < n:
		mini = puzz[i]
		maxi = puzz[i + stu]
		if maxi - mini < a:
			a = maxi - mini
print(a)


(n, m) = map(int, input().split())
s = input()
ss = s.split()
for x in range(m - 1):
	for y in range(m - 1 - x):
		if int(ss[y]) > int(ss[y + 1]):
			(ss[y], ss[y + 1]) = (ss[y + 1], ss[y])
q = 0
a = int(ss[n - 1]) - int(ss[0])
while True:
	if int(ss[q + n - 1]) - int(ss[q]) <= a:
		a = int(ss[q + n - 1]) - int(ss[q])
		q = q + 1
		if q > m - n:
			print(a)
			break
	else:
		q = q + 1
		if q > m - n:
			print(a)
			break


l = input().split()
n = int(l[0])
m = int(l[1])
min = 1000
A = 0
j = n - 1
n = n - 1
k = input().split()
for i in range(len(k)):
	k[i] = int(k[i])
k = sorted(k)
while j <= m - 1:
	A = k[j] - k[j - n]
	if min > A:
		min = A
	j = j + 1
print(min)


(n, m) = (int(i) for i in input().split())
l = sorted([int(i) for i in input().split()])
m1 = l[m - 1] - l[0]
for i in range(m - n + 1):
	if l[i + n - 1] - l[i] < m1:
		m1 = l[i + n - 1] - l[i]
print(m1)


(n, m) = map(int, input().split())
arr = sorted(list(map(int, input().split())))
diff = []
i = 0
while n <= m:
	temp = arr[n - 1] - arr[i]
	diff.append(temp)
	n = n + 1
	i = i + 1
print(min(diff))


s = str(input()).split()
n = int(s[0])
m = int(s[1])
p = str(input()).split()
for i in range(m):
	p[i] = int(p[i])
p.sort()
mn = p[-1] - p[0]
a = mn
for i in range(m - n + 1):
	a = p[n - 1 + i] - p[i]
	if a < mn:
		mn = a
print(mn)


(n, m) = map(int, input().split())
lis = list(map(int, input().split()))
lis = sorted(lis)
min_diff = 2 ** 30
for i in range(m - n + 1):
	if lis[i + n - 1] - lis[i] < min_diff:
		min_diff = lis[i + n - 1] - lis[i]
print(min_diff)


n = int(input().split()[0])
a = sorted(map(int, input().split()))
print(min((y - x for (x, y) in zip(a, a[n - 1:]))))


(n, m) = [int(x) for x in input().split()]
mList = [int(x) for x in input().split()]
mList.sort()
k = mList[n - 1] - mList[0]
for i in range(m - n + 1):
	k = min(k, mList[i + n - 1] - mList[i])
print(k)


(n, m) = input().split(' ')
n = int(n)
m = int(m)
a = [int(x) for x in input().split(' ')]
a = sorted(a)
s = a[m - 1]
for i in range(m - n + 1):
	if s > a[i + n - 1] - a[i]:
		s = a[i + n - 1] - a[i]
print(s)


num1 = list(map(int, input().split()))
num2 = list(map(int, input().split()))
num3 = sorted(num2, reverse=False)
num4 = []
for i in range(num1[1] - num1[0] + 1):
	num4.append(num3[i + num1[0] - 1] - num3[i])
print(min(num4))


(n, m) = map(int, input().split())
lst = sorted(list(map(int, input().split())))
ans = 1000
for i in range(m):
	try:
		ans = min(ans, lst[i + n - 1] - lst[i])
	except IndexError:
		pass
print(ans)


def rex():
	s = input().split(' ')
	m = int(s[0])
	n = int(s[1])
	x = input().split(' ')
	for i in range(n):
		x[i] = int(x[i])
	x = sorted(x)
	maxl = 1000
	for i in range(m - 1, n):
		val = x[i] - x[i - m + 1]
		if val < maxl:
			maxl = val
	return maxl
print(int(rex()))


str_first = input()
str_second = input()
list_first = str_first.split()
list_first = list(map(int, list_first))
list_second = str_second.split()
list_second = list(map(int, list_second))
list_second.sort()
domain = list_first[1] - list_first[0] + 1
answer = 1000
for i in range(0, domain):
	m = list_second[i + list_first[0] - 1] - list_second[i]
	if m < answer:
		answer = m
print(answer)


a = input()
b = a.split()
b = list(map(int, b))
d = input()
c = d.split()
c = list(map(int, c))
c.sort()
d = 1000000000
for i in range(b[1] - b[0] + 1):
	if d > c[b[0] + i - 1] - c[i]:
		d = c[b[0] + i - 1] - c[i]
print(d)


import os, sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(x, y) = map(int, input().split())
z = list(map(int, input().split()))
z = sorted(z)
b = len(z) // x
p = []
t1 = 0
while t1 + x <= y:
	q = [z[tt] for tt in range(t1, t1 + x)]
	t1 += 1
	p.append(max(q) - min(q))
print(min(p))


(n, _) = [int(x) for x in input().strip().split()]
list_in = sorted([int(x) for x in input().strip().split()])
list_re = [list_in[x + n - 1] - list_in[x] for x in range(len(list_in) - n + 1)]
if list_re:
	print(min(list_re))
else:
	print(0)


f = lambda : map(int, input().split())
(n, m) = f()
k = sorted(f())
a = {str(max(k))}
b = list()
for i in range(m - n + 1):
	s = k[i:i + n]
	l = max(s) - min(s)
	b.append(l)
print(min(b))


(n, m) = map(int, input().split(' '))
f = list(map(int, input().split(' ')))
f.sort()
puzzles_to_discard = m - n
if puzzles_to_discard == 0:
	least_possible_difference = f[-1] - f[0]
else:
	least_possible_difference = 999999
	i = 0
	while i <= puzzles_to_discard:
		difference_between_head_and_tail = f[n + i - 1] - f[i]
		if difference_between_head_and_tail < least_possible_difference:
			least_possible_difference = difference_between_head_and_tail
		i += 1
print(least_possible_difference)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
c = 2000
for i in range(m - n + 1):
	if c > a[i + n - 1] - a[i]:
		c = a[i + n - 1] - a[i]
print(c)


(M, N) = input().split()
m = int(M)
n = int(N)
a = input().split()
l = []
L = []
for i in a:
	l.append(int(i))
for i in range(len(l)):
	L.append(min(l))
	l.remove(min(l))
for i in range(n - m):
	x = []
	y = []
	for j in L[-m:]:
		x.append(max(L) - j)
	for k in L[:m]:
		y.append(k - min(L))
	if max(x) > max(y):
		L.remove(max(L))
	else:
		L.remove(min(L))
print(max(L) - min(L))


import sys
(n, m) = map(int, input().split())
lst = list(map(int, input().split()))
lst.sort(reverse=True)
(temp, answer) = (0, sys.maxsize)
for i in range(len(lst)):
	temp = 0
	if i + (n - 1) <= len(lst) - 1:
		temp = lst[i] - lst[i + n - 1]
		if temp < answer:
			answer = temp
print(answer)


(n, m) = input().split()
n = int(n)
m = int(m)
n = n - 1
f = input().split()
for i in range(len(f)):
	f[i] = int(f[i])
f.sort()
distance = f[n] - f[0]
for i in range(m - n):
	if f[n + i] - f[i] < distance:
		distance = f[n + i] - f[i]
print(distance)


lst = [int(x) for x in input().split()]
num_students = lst[0]
num_puzzles = lst[1]
puzzles = [int(x) for x in input().split()]
puzzles.sort()
smallest = 1000000000
for i in range(num_students - 1, len(puzzles)):
	temp = puzzles[i] - puzzles[i - num_students + 1]
	if temp < smallest:
		smallest = temp
print(smallest)


import sys
(n, m) = map(int, input().split())
array = list(map(int, input().split()))
array.sort()
izpis = [0] * (m - n + 1)
naj = 1000
if n == m:
	print(str(array[n - 1] - array[0]))
	sys.exit()
for i in range(0, m - n + 1):
	izpis[i] = array[i + n - 1] - array[i]
for j in range(0, m - n + 1):
	if izpis[j] < naj:
		naj = izpis[j]
print(str(naj))


(n, m) = [int(i) for i in input().split()]
a = sorted([int(i) for i in input().split()])
x = max(a) - min(a)
for i in range(m - n + 1):
	b = []
	for j in range(i, i + n):
		b.append(a[j])
	if max(b) - min(b) < x:
		x = max(b) - min(b)
print(x)


(n, m) = [int(x) for x in input().split(' ')]
puzzles = [int(x) for x in input().split(' ')]
puzzles.sort()
difference = [puzzles[i + n - 1] - puzzles[i] for i in range(m - n + 1)]
difference.sort()
print(difference[0])


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
i = 0
j = n - 1
mn = 1000000000.0
arr.sort()
while j < m:
	mn = min(mn, arr[j] - arr[i])
	i += 1
	j += 1
print(mn)


(n, m) = [int(i) for i in input().split()]
pazl = sorted([int(i) for i in input().split()])
r = max(pazl[:n]) - min(pazl[:n])
for i in range(m - n + 1):
	if pazl[n + i - 1] - pazl[i] < r:
		r = pazl[n + i - 1] - pazl[i]
print(r)


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


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
b = []
if m > n:
	for i in range(m - n + 1):
		c = a[i + n - 1] - a[i]
		b.append(c)
	print(min((x for x in b)))
else:
	print(a[-1] - a[0])


q = [int(i) for i in input().split()]
f = [int(i) for i in input().split()]
f.sort()
(l, r) = (0, q[0] - 1)
m = 1000
for i in range(q[1] - q[0] + 1):
	t = f[i + q[0] - 1] - f[i]
	if t < m:
		m = t
print(m)


(n, m) = [int(i) for i in input().split()]
shop = sorted([int(i) for i in input().split()])
result = []
for (n_i, i) in enumerate(shop):
	if n + n_i > m:
		break
	result.append(abs(i - shop[n_i + n - 1]))
print(min(result))


(n, m) = [int(x) for x in input().split()]
num = [int(x) for x in input().split()]
min = 10000
num.sort()
i = n - 1
while i < m:
	if num[i] - num[i - n + 1] < min:
		min = num[i] - num[i - n + 1]
	i += 1
print(min)


(n, m) = map(int, input().split())
l = list(map(int, input().strip().split()))[:m]
l.sort()
i = 0
j = n - 1
k = l[j] - l[i]
while j < m - 1:
	if k > l[j + 1] - l[i + 1]:
		k = l[j + 1] - l[i + 1]
	j = j + 1
	i = i + 1
print(k)


(n, m) = map(int, input().strip().split())
x = list((int(i) for i in input().strip().split()))
x.sort()
s = x[n - 1] - x[0]
for i in range(m - n + 1):
	s = min(s, x[n + i - 1] - x[i])
print(s)


(n, m) = map(int, input().split())
jigsaws = [int(x) for x in input().split()]
jigsaws.sort()
maxdif = None
for i in range(m - n + 1):
	dif = jigsaws[i + n - 1] - jigsaws[i]
	if maxdif == None or maxdif > dif:
		maxdif = dif
print(maxdif)


(n, m) = map(int, input().split())
p = sorted(map(int, input().split()))
least = abs(p[0] - p[n - 1])
for i in range(m - n + 1):
	if abs(p[i] - p[n + i - 1]) < least:
		least = abs(p[i] - p[n + i - 1])
print(least)


(n, m) = map(int, input().split())
arr = sorted(list(map(int, input().split())))
min_diff = 100000000000000000000
for i in range(n - 1, m):
	var = arr[i] - arr[i - n + 1]
	if var < min_diff:
		min_diff = var
print(min_diff)


s = list(map(int, input().split()))
m = list(map(int, input().split()))
a = s[0]
b = s[1]
m.sort()
e = []
for i in range(b - a + 1):
	k = m[i + a - 1] - m[i]
	e.append(k)
print(min(e))


(x, y) = input().split(' ')
x = int(x)
y = int(y)
list1 = [int(i) for i in input().split()]
list1.sort()
min = list1[y - 1]
for i in range(0, y - x + 1):
	if list1[i + x - 1] - list1[i] < min:
		min = list1[i + x - 1] - list1[i]
if y - x == 0:
	print(list1[y - 1] - list1[0])
else:
	print(min)


(a, b) = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
minum = 10000
i = 0
while i + a < b + 1:
	minum = min(c[i + a - 1] - c[i], minum)
	i = i + 1
print(minum)


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def rinput():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
(n, m) = rinput()
s = list(map(int, input().split()))
s = sorted(s)
ans = 99999
for i in range(n - 1, m):
	ans = min(ans, s[i] - s[i - n + 1])
print(ans)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
b = 1000000000
for i in range(len(a)):
	if i + n - 1 <= len(a) - 1:
		b = min(b, a[i + n - 1] - a[i])
print(b)


l1 = [int(x) for x in input().split()]
l2 = [int(x) for x in input().split()]
n = l1[0]
m = l1[1]
l2.sort()
i = 0
ans = max(l2) - min(l2)
while i < m - n + 1:
	temp = l2[i + n - 1] - l2[i]
	ans = min(temp, ans)
	i += 1
print(ans)


(n, k) = input().split()
ls = list(map(int, input().split()))
ls.sort()
mi = []
for i in range(int(k) - int(n) + 1):
	mi.append(ls[int(n) + i - 1] - ls[i])
if len(mi) == 0:
	print(0)
else:
	print(min(mi))


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
arr = sorted(arr)
diff = 99999999
if m == n:
	print(arr[m - 1] - arr[0])
	exit()
for i in range(0, m - n + 1):
	temp = arr[i + n - 1] - arr[i]
	if temp < diff:
		diff = temp
print(diff)


a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
m = a[0]
n = a[1]
b.sort()
k = 0
c = []
if m != n:
	while k + m - 1 != n:
		c.append(b[k + m - 1] - b[k])
		k += 1
	print(min(c))
else:
	print(max(b) - min(b))


(n, m) = map(int, input().split())
a = [int(s) for s in input().split()]
a.sort()
md = -1
d = 0
for i in range(n - 1, m):
	d = a[i] - a[i - n + 1]
	if md == -1 or md > d:
		md = d
print(md)


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


n = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))
diff = a[n[0] - 1] - a[0]
for i in range(n[1] - n[0] + 1):
	tdiff = a[i + n[0] - 1] - a[i]
	if tdiff < diff:
		diff = tdiff
print(diff)


import math
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
i = 0
j = n - 1
mi = math.inf
while j < len(a):
	num = a[j] - a[i]
	if num < mi:
		mi = num
	i += 1
	j += 1
print(mi)


nm = input().split(' ')
n = int(nm[0])
m = int(nm[1])
f = list(map(int, input().split(' ')))
f.sort()
d = []
if m == n:
	d.append(int(f[-1]) - int(f[0]))
else:
	for i in range(m - n + 1):
		x = int(f[i + n - 1]) - int(f[i])
		d.append(x)
print(min(d))


import sys

def data():
	return sys.stdin.readline().strip()

def sp():
	return map(int, data().split())

def l():
	return list(sp())

def ans(pl, n, m):
	temp = sorted(pl)
	mn = temp[-1] - temp[0]
	for i in range(m - n + 1):
		res = temp[i:i + n]
		diff = res[-1] - res[0]
		if mn > diff:
			mn = diff
	return mn
(n, m) = l()
pl = l()
print(ans(pl, n, m))


(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
s = 10000000000000000000
for i in range(len(a) - n + 1):
	s = min(s, a[i + n - 1] - a[i])
print(s)


(n, m) = [int(x) for x in input().split()]
v = [int(x) for x in input().split()]
v.sort()
minv = 1000
for i in range(0, m - n + 1):
	minv = min(minv, v[i + n - 1] - v[i])
print(minv)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
i = 0
v = []
c = 0
while c < k:
	c = i + n - 1
	if c >= k:
		break
	v.append(l[c] - l[i])
	i += 1
print(min(v))


(n, k) = list(map(int, input().split(' ')))
arr = list(map(int, input().split(' ')))
arr.sort()
arrs = []
for x in range(0, k + n):
	if n + x <= len(arr):
		arrs.append(arr[x:n + x])
arrs.sort(key=lambda x: max(x) - min(x))
print(max(arrs[0]) - min(arrs[0]))


(m, n) = map(int, input().split())
s = []
items = sorted(list(map(int, input().split())))
for i in range(n - m + 1):
	x = items[i + m - 1] - items[i]
	s.append(x)
print(min(s))


(n, m) = map(int, input().split())
list1 = sorted(list(map(int, input().split())))
m1 = max(list1) - min(list1)
for i in range(m - n + 1):
	d = list1[i + n - 1] - list1[i]
	if d < m1:
		m1 = d
print(m1)


(n, m) = map(int, input().split())
num = [int(x) for x in input().split()]
num.sort()
minn = 1000000000000
for i in range(0, m - n + 1):
	minn = min(minn, num[i + n - 1] - num[i])
print(minn)


(n, m) = [int(x) for x in input().split()]
L = [int(x) for x in input().split()]
L.sort()
i = 0
M = []
while i + n <= m:
	M.append(max(L[i:i + n]) - min(L[i:i + n]))
	i += 1
print(min(M))


(n, m) = map(int, input().split())
piece = input().split()
piece1 = []
for i in piece:
	piece1.append(int(i))
piece1.sort(reverse=True)
t = 0
output = 1000
while t < m - n + 1:
	difference = piece1[t] - piece1[t + n - 1]
	if difference < output:
		output = difference
	t = t + 1
print(output)


(n, m) = (int(x) for x in input().split())
a = sorted(list((int(x) for x in input().split())))
mini = 0
for i in range(len(a) - n + 1):
	j = i + n - 1
	x = abs(a[i] - a[j])
	if i == 0:
		mini = x
	elif x < mini:
		mini = x
print(mini)


(n, m) = map(int, input().split())
a = [int(x) for x in input().split()]
a = sorted(a)
M = 1000000000
for i in range(n - 1, m):
	M = min(M, a[i] - a[i - (n - 1)])
print(M)


from sys import stdin, stdout
(n, m) = map(int, stdin.readline().split(' '))
lis = [int(x) for x in stdin.readline().split(' ')]
lis.sort()
minwa = lis[n - 1] - lis[0]
for i in range(m - n + 1):
	if lis[i + (n - 1)] - lis[i] < minwa:
		minwa = lis[i + (n - 1)] - lis[i]
print(minwa)


(n, m) = map(int, input().split())
f = sorted([int(x) for x in input().split()])
d = []
for i in range(m - n + 1):
	d.append(f[i + n - 1] - f[i])
print(min(d))


(n, m) = map(int, input().split())
arr = [int(i) for i in input().split()]
arr.sort()
mn = arr[-1] - arr[0]
for i in range(m - n + 1):
	mn = min(mn, arr[i + n - 1] - arr[i])
print(mn)


(n, m) = map(int, input().split())
li = list(map(int, input().split()))
li.sort()
i = 0
j = n - 1
tmp = 0
res = 99999999999999
while j != m:
	tmp = abs(li[i] - li[j])
	res = min(tmp, res)
	i += 1
	j += 1
print(res)


(n, m) = [int(x) for x in input().split()]
f = list(map(int, input().split()))
fm = sorted(f)
maxf = max(f)
minf = min(f)
if m == n:
	print(maxf - minf)
else:
	num = maxf - minf
	for i in range(m - n + 1):
		k = fm[i + n - 1] - fm[i]
		num = min(k, num)
	print(num)


data = list(map(int, input().split()))
puzzles = list(map(int, input().split()))
puzzles.sort()
variants = []
for i in range(0, len(puzzles)):
	if i + data[0] - 1 < len(puzzles):
		variants.append(puzzles[i + data[0] - 1] - puzzles[i])
print(min(variants))


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
c = 1000
for i in range(m - n + 1):
	x = l[i:i + n]
	y = max(x) - min(x)
	if c > y:
		c = y
print(c)


x = input()
(n, m) = list(map(int, x.strip().split(' ')))
puzzle = input()
puzzle = list(map(int, puzzle.strip().split()))
puzzle.sort()
mini = 1000
i = 0
while i + n - 1 < len(puzzle):
	razlika = puzzle[i + n - 1] - puzzle[i]
	if razlika < mini:
		mini = razlika
	i = i + 1
print(mini)


[a, b] = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
c.sort()
d = []
for i in range(b - a + 1):
	d.append(c[i + a - 1] - c[i])
print(min(d))


(n, m) = map(int, input().split())
pie = input().split()
for i in range(m):
	pie[i] = int(pie[i])
pie.sort()
pie.reverse()
max = pie[0] - pie[n - 1]
i = 0
while i < m - n + 1:
	if pie[i] - pie[i + n - 1] < max:
		max = pie[i] - pie[i + n - 1]
	i = i + 1
print(str(max))


import math
(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
diff = 0
arr.sort(reverse=True)
mini = math.inf
for i in range(m - n + 1):
	diff = arr[i] - arr[i + n - 1]
	if diff < mini:
		mini = diff
print(mini)


(n, m) = input().split()
n = int(n)
s = 2
lis = sorted([int(x) for x in input().split()])
mi = []
for i in range(len(lis) - n + 1):
	sub = lis[i + n - 1] - lis[i]
	mi.append(sub)
print(min(mi))


(n, m) = input().split()
n = int(n)
m = int(m)
p = input().split()
for i in range(m):
	p[i] = int(p[i])
p.sort()
min = p[n - 1] - p[0]
for i in range(0, m - n + 1):
	if p[i + n - 1] - p[i] < min:
		min = p[i + n - 1] - p[i]
print(min)


(n, m) = [int(i) for i in input().split()]
pazzle_count = [int(i) for i in input().split()]
pazzle_count_sorted = sorted(pazzle_count)
min = max(pazzle_count)
i = 0
while min != 0 and i + n <= m:
	mini = pazzle_count_sorted[i + n - 1] - pazzle_count_sorted[i]
	if mini < min:
		min = mini
	i += 1
print(min)


(n, m) = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
l.sort()
ans = 1000000000.0
for i in range(m - n + 1):
	ans = min(ans, l[i + n - 1] - l[i])
print(ans)


(n, m) = map(int, input().split())
l = sorted([int(i) for i in input().split()], reverse=True)
diff = 0
ld = []
for i in range(m - n + 1):
	diff = l[i] - l[i + n - 1]
	ld.append(diff)
ld = sorted(ld)
print(ld[0])


def main():
	(n, m) = map(int, input().split())
	v = list(map(int, input().split()))
	v.sort()
	s = 1000 * 50
	for i in range(n, m + 1):
		s = min(v[i - 1] - v[i - n], s)
	print(s)
main()


data = [int(x) for x in input().split(' ')]
pieces = [int(x) for x in input().split(' ')]
pieces.sort()
ans = 999999999
if data[0] == data[1]:
	print(pieces[data[0] - 1] - pieces[0])
else:
	for x in range(data[0] - 1, len(pieces)):
		ans = min(ans, pieces[x] - pieces[x + 1 - data[0]])
	print(ans)


(n, m) = map(int, input().split())
q = [int(i) for i in input().split()]
q.sort()
q.reverse()
p = 0
for i in range(m - n + 1):
	if i == 0:
		p = abs(q[i] - q[i + n - 1])
	elif abs(q[i] - q[i + n - 1]) > p:
		p = p
	else:
		p = abs(q[i] - q[i + n - 1])
print(p)


import sys
s = input().strip().split()
(n, m) = (int(s[0]), int(s[1]))
lst = [int(i) for i in input().strip().split()]
lst.sort()
minimum = sys.maxsize
cur_min = minimum
for i in range(m - n + 1):
	smallest = lst[i]
	largest = lst[i + n - 1]
	cur_min = largest - smallest
	if cur_min < minimum:
		minimum = cur_min
print(minimum)


(m, n) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
t = 0
r = 0
i = 0
j = m - 1
while j < n:
	if t == 0:
		r = arr[j] - arr[i]
		t += 1
	elif r > arr[j] - arr[i]:
		r = arr[j] - arr[i]
	if r == 0:
		break
	i += 1
	j += 1
print(r)


(n, m) = map(int, input().split())
a = input().split()
for i in range(m):
	a[i] = int(a[i])
a.sort()
answer = 0
ma = 1000000000000000
k = 0
for i in range(m - n + 1):
	if a[i + n - 1] - a[i] < ma:
		ma = a[i + n - 1] - a[i]
		k += 1
if k != 0:
	answer = ma
print(answer)


(n, m) = [int(x) for x in input().split()]
puzzle = input().split()
if len(puzzle) <= m:
	new_puzzle_list = []
	for i in puzzle:
		new_puzzle_list.append(int(i))
	new_puzzle_list.sort()
	min_delta = 10000
	for i in range(n, m + 1):
		min_delta = min(abs(new_puzzle_list[i - 1] - new_puzzle_list[i - n]), min_delta)
	print(min_delta)


(n, m) = input().split()
n = int(n)
m = int(m)
arr = [int(x) for x in input().split()]
arr.sort()
min = 1000
for i in range(0, m - n + 1):
	diff = arr[n + i - 1] - arr[i]
	if diff < min:
		min = diff
print(min)


(n, m) = map(int, input().split())
d = list(map(int, input().split()))
d.sort(reverse=True)
dif = d[0] - d[n - 1]
for i in range(1, len(d) - n + 1):
	cur = d[i] - d[i + n - 1]
	dif = min(cur, dif)
print(dif)


def bubble_sort(A):
	for bypass in range(1, len(A)):
		for k in range(len(A) - bypass):
			if A[k] > A[k + 1]:
				(A[k], A[k + 1]) = (A[k + 1], A[k])
	return A
(n, m) = input().split()
n = int(n)
m = int(m)
puzzles = input().split()
for i in range(m):
	puzzles[i] = int(puzzles[i])
puzzles = bubble_sort(puzzles)
res = max(puzzles) * 2
for i in range(m - n + 1):
	if abs(puzzles[i] - puzzles[i + n - 1]) < res:
		res = abs(puzzles[i] - puzzles[i + n - 1])
print(res)


(n_students, n_puzzles) = [int(i) for i in input().split(' ')]
puzzle_sizes = [int(i) for i in input().split(' ')]
puzzle_sizes = sorted(puzzle_sizes)
best_diff = 10000
for i in range(n_puzzles - n_students + 1):
	diff = puzzle_sizes[i + n_students - 1] - puzzle_sizes[i]
	best_diff = min(best_diff, diff)
print(best_diff)


(n, k) = map(int, input().split())
l = sorted(list(map(int, input().split())))
c = l[k - 1]
for i in range(k - n + 1):
	p = l[i + n - 1] - l[i]
	if c > p:
		c = p
print(c)


nm = input().split()
n = int(nm[0])
m = int(nm[1])
A = input().split()
A = [int(i) for i in A]
for i in range(0, m):
	for j in range(i, m):
		if A[i] > A[j]:
			temp = A[j]
			A[j] = A[i]
			A[i] = temp
min = 1000
for i in range(0, m - n + 1):
	if min > A[i + n - 1] - A[i]:
		min = A[i + n - 1] - A[i]
print(min)


def min_differences(n_children: int, n_presents: int, present_pieces: list) -> int:
	present_pieces = sorted(present_pieces)
	diffs = [present_pieces[j + n - 1] - present_pieces[j] for j in range(m - n + 1)]
	return min(diffs)
(n, m) = map(int, input().split())
f = [int(i) for i in input().split()]
print(min_differences(n, m, f))


(student, puzzle) = input().split()
data = [int(i) for i in input().split()]
data.sort()
_min = 99999
for i in range(int(student) - 1, int(puzzle)):
	_min = min(_min, data[i] - data[i - int(student) + 1])
print(_min)


(n, m) = map(int, input().strip().split())
p = list(map(int, input().strip().split()))
p.sort()
ans = 9999999
for i in range(m - n + 1):
	d = p[i + n - 1] - p[i]
	ans = min(ans, d)
print(ans)


a = input()
b = input()
c = a.split()
d = b.split()
e = []
for j in d:
	e.append(int(j))
k = int(c[0])
m = int(c[1])
f = sorted(e)
i = 0
w = []
while i <= m - k:
	t = f[i + k - 1] - f[i]
	w.append(t)
	i += 1

def min_in_list(lst):
	g = lst[0]
	for l in lst:
		if l < g:
			g = l
	return g
r = min_in_list(w)
idx = w.index(r)
p = []
for s in range(k):
	p.append(f[idx])
	idx += 1
print(p[k - 1] - p[0])


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


(n, m) = map(int, input().split())
lst = list(map(int, input().split()))
lst.sort()
difference = []
for i in range(len(lst) - n + 1):
	difference.append(lst[i + n - 1] - lst[i])
first = difference[0]
for item in difference:
	if item < first:
		first = item
print(first)


(n, m) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a = sorted(a)
min = a[n - 1] - a[0]
for i in range(m - n + 1):
	if a[i + n - 1] - a[i] < min:
		min = a[i + n - 1] - a[i]
print(min)


(n, m) = map(int, input().split(' '))
l = list(map(int, input().split(' ')))
l.sort()
if n == m:
	print(l[-1] - l[0])
else:
	temp = l[-1]
	for i in range(len(l) - n + 1):
		temp2 = l[i:i + n]
		if temp2[-1] - temp2[0] < temp:
			temp = temp2[-1] - temp2[0]
	print(temp)


(a, b) = map(int, input().split())
arr = sorted(list(map(int, input().split())))
m = []
low = 0
high = a
while high <= len(arr):
	m.append(max(arr[low:high]) - min(arr[low:high]))
	low += 1
	high += 1
print(min(m))


(n, m) = map(int, input().split())
l = [int(i) for i in input().split()]
l.sort(reverse=True)
s = l[0] - l[n - 1]
for i in range(m - n + 1):
	t = l[i] - l[i + n - 1]
	if t < s:
		s = t
print(s)


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


(n, m) = input().split()
(n, m) = (int(n), int(m))
s = input().split()
ss = []
for i in s:
	ss += [int(i)]
ss = sorted(ss)
ans = 100000000000000000000000
for i in range(len(ss)):
	if i + n - 1 >= len(ss):
		break
	else:
		ans = min(ans, ss[i + n - 1] - ss[i])
print(ans)


__author__ = 'runekri3'
(n, m) = list(map(int, input().split()))
puzzles = list(map(int, input().split()))
puzzles.sort(reverse=True)
min_difference = 9001
for (i, puzzle) in enumerate(puzzles):
	try:
		difference = puzzle - puzzles[i + n - 1]
	except IndexError:
		break
	if difference < min_difference:
		min_difference = difference
print(min_difference)


(n, m) = [int(x) for x in input().split()]
pzls = [int(x) for x in input().split()]
pzls.sort()
smallest = 10000000000000
for i in range(len(pzls) - n + 1):
	smallest = min(smallest, abs(pzls[i] - pzls[i + n - 1]))
print(smallest)


(n, m) = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
A.sort()
if m == 2:
	Min = A[1] - A[0]
else:
	Min = A[n - 1] - A[0]
	for i in range(m - n + 1):
		if A[i + n - 1] - A[i] < Min:
			Min = A[i + n - 1] - A[i]
print(Min)


(n, m) = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
l.sort()
if m == n:
	print(max(l) - min(l))
else:
	d = []
	for i in range(m - n + 1):
		d.append(l[i + n - 1] - l[i])
	print(min(d))


(m, n) = map(int, input().split())
a = [int(i) for i in input().split()]
a = sorted(a)
x = 0
y = m
b = []
while y != n + 1:
	ma = max(a[x:y])
	mi = min(a[x:y])
	b.append(ma - mi)
	x += 1
	y += 1
print(min(b))


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort(reverse=True)
ans = 100000
num = abs(n - m) + 1
for i in range(num):
	if l[i] - l[i + n - 1] < ans:
		ans = l[i] - l[i + n - 1]
print(ans)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
minimo = a[-1]
c = 0
while m - n >= c:
	diff = a[c + n - 1] - a[c]
	c += 1
	if minimo > diff:
		minimo = diff
print(minimo)


(n, m) = map(int, input().split())
values = map(int, input().split())
values = sorted(values)
val = None
for i in range(n - 1, m):
	value = values[i] - values[i - n + 1]
	if val is None:
		val = value
	else:
		val = min(val, value)
print(val)


p = []
(n, m) = input().split()
l = [int(x) for x in input().split()]
l.sort()
for i in range(0, int(m) - int(n) + 1):
	p.append(l[i + int(n) - 1] - l[i])
p.sort()
print(p[0])


(n, m) = map(int, input().split())
x = input().split()
for i in range(m):
	x[i] = int(x[i])
x.sort()
min = 10000
for i in range(m - n + 1):
	if x[i + n - 1] - x[i] < min:
		min = x[i + n - 1] - x[i]
print(min)


def mimimumDifference(puzzles, amount):
	minimum = 99999999999
	puzzles.sort()
	for i in range(0, len(puzzles) - int(amount) + 1):
		if int(puzzles[i + int(amount) - 1]) - int(puzzles[i]) < minimum:
			minimum = int(puzzles[i + int(amount) - 1]) - int(puzzles[i])
	if len(puzzles) - int(amount) == 0:
		minimum = int(puzzles[-1]) - int(puzzles[0])
	return minimum
i = input().split(' ')
print(mimimumDifference(list(map(int, input().split(' '))), i[0]))


def Sol(k, arr):
	arr.sort()
	diff = arr[-1]
	for x in range(k - 1, len(arr)):
		d = arr[x] - arr[x - (k - 1)]
		diff = min(d, diff)
	print(diff)
	return
(s, n) = map(int, input().split())
arr = list(map(int, input().split()))
Sol(s, arr)


(n, m) = map(int, input().split())
f = sorted(map(int, input().split()))
print(min((high - low for (low, high) in zip(f, f[n - 1:]))))


b = list(map(int, input().split()))
c = list(map(int, input().split()))
m = b[1]
n = b[0]
c.sort()
low_diff = c[len(c) - 1] - c[0]
i = n - 1
while i < m:
	if c[i] - c[i + 1 - n] < low_diff:
		low_diff = c[i] - c[i + 1 - b[0]]
	i += 1
print(low_diff)


(num_stud, num_puzz) = map(int, input().split())
lst = list(map(int, input().split()))
lst = sorted(lst)
maxim = 9999
for i in range(num_puzz - num_stud + 1):
	maxim = min(maxim, lst[i + num_stud - 1] - lst[i])
print(maxim)


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


ln = input().split(' ')
ll = int(ln[0])
pp = int(ln[1])
aa = input().split(' ')
for x in range(pp):
	aa[x] = int(aa[x])
aa.sort()
ans = 9999
for x in range(pp - ll + 1):
	ans = min(ans, aa[x + ll - 1] - aa[x])
print(ans)


(n, m) = map(int, input().strip().split(' '))
f = list(map(int, input().strip().split(' ')))
f.sort()
min_f = 1000
for i in range(m - n + 1):
	divers = max(f[i:i + n]) - min(f[i:i + n])
	if divers < min_f:
		min_f = divers
print(min_f)


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


(n, m) = map(int, input().split())
l = [int(x) for x in input().split()]
l.sort()
l1 = [x for x in range(n)]
x = abs(l[0] - l[-1])
for i in range(m - n + 1):
	for j in range(n):
		l1[j] = l[i + j]
	x = min(abs(l1[0] - l1[-1]), x)
print(x)


(n, m) = map(int, input().split())
n -= 1
a = sorted(map(int, input().split()), reverse=True)
mi = a[0] - a[n]
for i in range(1, m - n):
	mi = min(mi, a[i] - a[i + n])
print(mi)


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


import sys
from math import *

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())
(n, m) = mints()
f = list(mints())
f.sort()
r = 1e+100
for i in range(m - n + 1):
	r = min(r, f[i + n - 1] - f[i])
print(r)


import sys

def main():
	i = 0
	ipt = []
	for line in sys.stdin:
		line = list(map(int, line.split()))
		ipt.append(line)
	(purchase, size) = (ipt[0][0], ipt[0][1])
	ipt_arr = ipt[1]
	opt = puzzle(purchase, ipt_arr, size)
	print(opt)

def puzzle(purchase, ipt_arr, size):
	ipt_arr = sorted(ipt_arr)
	i = purchase - 1
	j = 0
	diff = 100000
	while i < size:
		diff = min(diff, ipt_arr[i] - ipt_arr[j])
		i += 1
		j += 1
	return diff
main()


__author__ = 'Utena'
(n, m) = map(int, input().split())
s = sorted(list(map(int, input().split())))
a = s[m - 1] - s[0]
for i in range(m - n + 1):
	if s[i + n - 1] - s[i] < a:
		a = s[i + n - 1] - s[i]
print(a)


(n_students, m_puzzles) = [int(elem) for elem in input().split(' ')]
pieces = [int(elem) for elem in input().split(' ')]
for i in range(m_puzzles):
	for j in range(1, m_puzzles):
		if pieces[j] < pieces[j - 1]:
			(pieces[j], pieces[j - 1]) = (pieces[j - 1], pieces[j])
min_ = 1000
for i in range(m_puzzles - (n_students - 1)):
	diff = pieces[i + (n_students - 1)] - pieces[i]
	if diff < min_:
		min_ = diff
print(min_)


s = input()
(n, m) = s.split()
n = int(n)
m = int(m)
s1 = input()
s2 = s1.split()
lst = []
c = 0
lst1 = []
for i in s2:
	lst.append(int(i))
lst.sort()
for i in range(m):
	if n + i - 1 >= m:
		break
	else:
		c = lst[n - 1 + i] - lst[i]
		lst1.append(c)
		c = 0
print(min(lst1))


(n, m) = map(int, input().split())
pieces = [int(x) for x in input().split()]
pieces.sort()
print(min((pieces[n + i - 1] - pieces[i] for i in range(m - n + 1))))


(m, n) = list(map(int, input().split()))
data = list(map(int, input().split()))
data.sort()

def get_diff(d):
	return d[-1] - d[0]
minn = data[-1] - data[0]
for i in range(n - m + 1):
	if get_diff(data[i:m + i]) < minn:
		minn = get_diff(data[i:m + i])
print(minn)


X = [int(x) for x in input().split()]
Y = [int(x) for x in input().split()]
Y.sort()
M = []
B = []
for x in Y:
	if x not in M:
		M.append(x)
		B.append(1)
	else:
		N = M.index(x)
		B[N] = B[N] + 1
N = len(B)
if max(B) >= X[0]:
	D = 0
else:
	d = []
	j = 0
	while j < N:
		i = j
		h = 0
		while h < X[0]:
			h = h + B[i]
			i = i + 1
			if i == N:
				break
		if h >= X[0]:
			d.append(M[i - 1] - M[j])
		j = j + 1
	D = min(d)
print(D)


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


a1 = input()
a = a1.split()
b1 = input()
b = b1.split()
b = list(map(int, b))
b.sort()
n = int(a[0])
m = int(a[1])
y = m - n
k = 1000
for i in range(y + 1):
	if int(b[i + n - 1]) - int(b[i]) < k:
		k = int(b[i + n - 1]) - int(b[i])
print(k)


from sys import stdin, stdout
from itertools import combinations
(nstudents, npuzzles) = [int(x) for x in stdin.readline().rstrip().split()]
pieces = [int(x) for x in stdin.readline().rstrip().split()]
pieces.sort()
res = float('inf')
(i, j) = (0, nstudents - 1)
while j < npuzzles:
	res = min(res, pieces[j] - pieces[i])
	(i, j) = (i + 1, j + 1)
stdout.write(str(res) + '\n')


(n, m) = [int(x) for x in input().split(' ')]
puzzles = [int(x) for x in input().split(' ')]
puzzles.sort()
minDif = 9999999999
if m - n == 0:
	minDif = abs(max(puzzles) - min(puzzles))
else:
	for i in range(0, m - n + 1):
		minDif = min(minDif, abs(max(puzzles[i:n + i]) - min(puzzles[i:n + i])))
print(minDif)


from math import *
from collections import *
import sys
sys.setrecursionlimit(10 ** 9)
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
minn = a[n - 1] - a[0]
for i in range(m - n + 1):
	minn = min(minn, a[i + n - 1] - a[i])
print(minn)


def function(n, m, p):
	rDiff = 100000000
	prev = rDiff
	for i in range(m - n + 1):
		rDiff = selection(n, m, p, i)
		if rDiff < prev:
			prev = rDiff
			result = p[i:i + n]
	return result[0] - result[-1]

def selection(n, m, p, i):
	res = p[i:i + n]
	diff = res[0] - res[-1]
	return diff
(n, m) = input().split()
(n, m) = (int(n), int(m))
pTemp = list(input().split())
p = []
for i in pTemp:
	temp = int(i)
	p.append(temp)
p.sort()
p.reverse()
print(function(n, m, p))


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
mini = 10 ** 6
a.sort()
for i in range(m - n + 1):
	x = max(a[i:i + n]) - min(a[i:i + n])
	if x < mini:
		mini = x
print(mini)


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
f = sorted(f)
minfir = []
for i in range(m):
	if i + n - 1 == m:
		break
	else:
		minfir.append(f[i + n - 1] - f[i])
print(min(minfir))


(students_cnt, pazzles_cnt) = map(int, input().split())
fragments = sorted(map(int, input().split()))
min_diff = None
for index in range(0, len(fragments) - students_cnt + 1):
	if min_diff is None:
		min_diff = fragments[index + students_cnt - 1] - fragments[index]
	min_diff = min(fragments[index + students_cnt - 1] - fragments[index], min_diff)
print(min_diff or 0)


(n, m) = input().split(' ')
a = input().split(' ')
for w in range(int(m)):
	a[w] = int(a[w])
a.sort()
c = a[int(n) - 1] - a[0]
for i in range(0, int(m) - int(n) + 1):
	cf = a[int(n) - 1 + i] - a[i]
	if c > cf:
		c = cf
print(c)


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


import math
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
x = math.inf
for i in range(len(a) - n + 1):
	x = min(x, a[i + n - 1] - a[i])
print(x)


(n, m) = [int(x) for x in input().split()]
list = [int(x) for x in input().split()]
list.sort()
min = list[m - 1] - list[0]
for x in range(m - n + 1):
	sum = list[n + x - 1] - list[x]
	if sum < min:
		min = sum
print(min)


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


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = i = 0
m1 = 1001
m2 = -1
b = []
while i < n:
	b.append(a[i])
	m1 = min(m1, a[i])
	m2 = max(m2, a[i])
	i = i + 1
ans = m2 - m1
for j in range(i, m):
	b.pop(0)
	b.append(a[j])
	m1 = min(b)
	m2 = max(b)
	ans = min(ans, m2 - m1)
print(ans)


(m, n) = list(map(int, input().split()))
plist = sorted(list(map(int, input().split())))
div = []
if n - m > 0:
	for i in range(n - m + 1):
		div.append(plist[i + m - 1] - plist[i])
	print(min(div))
else:
	print(plist[-1] - plist[0])


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


(n, m) = map(int, input().split())
s = list(map(int, input().split()))
s.sort()
dec = []
for i in range(0, len(s) - n + 1):
	x = s[i + n - 1] - s[i]
	dec.append(x)
print(min(dec))


nm = [int(e) for e in input().split()]
n = nm[0]
m = nm[1]
l = []
p = [int(e) for e in input().split()]
p.sort()
for i in range(m - n + 1):
	l.append(p[i + n - 1] - p[i])
print(min(l))


(n, m) = [int(x) for x in input().split()]
A = sorted([int(x) for x in input().split()])
B = []
if n == m:
	print(max(A) - min(A))
else:
	for i in range(m - n + 1):
		B.append(A[i + n - 1] - A[i])
	print(min(B))


line1 = input().split()
n = int(line1[0])
m = int(line1[1])
line = input().split()
L = []
for i in range(m):
	L.append(int(line[i]))
L = sorted(L)
if m == n:
	print(int(L[m - 1]) - int(L[0]))
else:
	a = m - n
	Min = int(L[n - 1]) - int(L[0])
	for i in range(a + 1):
		if int(L[i + n - 1]) - int(L[i]) < Min:
			Min = int(L[i + n - 1]) - int(L[i])
	print(Min)


(n, m) = list((int(x) for x in input().split()))
a = list(map(int, input().split()))
a.sort()
b = 10000
for i in range(0, m - n + 1):
	d = a[i + n - 1] - a[i]
	if d < b:
		b = d
print(b)


def main():
	a = []
	(n, m) = input().split()
	(n, m) = (int(n), int(m))
	r = sorted(list(map(int, input().split())))
	rr = 1000
	for i in range(m - n + 1):
		rr = min(rr, r[i + n - 1] - r[i])
	print(rr)
main()


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
f.sort()
temp = 5000
for i in range(m - n + 1):
	temp = min(temp, f[i + n - 1] - f[i])
print(temp)


(n, m) = map(int, input().split())
puzzles = [int(x) for x in input().split()]
puzzles.sort()
min_diff = puzzles[m - 1] - puzzles[0]
for i in range(m - n + 1):
	if puzzles[i + n - 1] - puzzles[i] < min_diff:
		min_diff = puzzles[i + n - 1] - puzzles[i]
print(min_diff)


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
f.sort()
a = 0
b = a + (n - 1)
t = f[b] - f[a]
while b < m:
	t = min(t, f[b] - f[a])
	a += 1
	b += 1
print(t)


temp = list(map(int, input().rstrip().split()))
n = temp[0]
m = temp[1]
arr = list(map(int, input().rstrip().split()))
arr.sort()
minDiff = 10000
for j in range(n - 1, m):
	diff = arr[j] - arr[j - (n - 1)]
	if diff < minDiff:
		minDiff = diff
print(minDiff)


(n, m) = map(int, input().split())
l = list(sorted(map(int, input().split())))
diff = 1001
for i in range(0, len(l) - n + 1):
	diff = min(diff, l[i + n - 1] - l[i])
print(diff)


import sys
(n, m) = [int(el) for el in sys.stdin.readline().strip().split()]
f = [int(el) for el in sys.stdin.readline().strip().split()]
f.sort()
minimum = 10000000
for i in range(0, m - n + 1):
	minimum = min(minimum, f[i + n - 1] - f[i])
print(minimum)


(n, m) = map(int, input().split(' '))
fs = sorted(map(int, input().split(' ')))
print(min((b - a for (a, b) in zip(fs, fs[n - 1:]))))


(n, m) = list(map(int, input().split()))
f = list(map(int, input().split()))
f.sort()
begin_position_mark = 1
end_position_mark = n
begin_value_mark = f[0]
end_value_mark = f[n - 1]
_min = end_value_mark - begin_value_mark
while end_position_mark < m:
	if f[end_position_mark] - f[begin_position_mark] < _min:
		_min = f[end_position_mark] - f[begin_position_mark]
	begin_position_mark += 1
	end_position_mark += 1
print(_min)


def merge_sort(string):
	if len(string) == 1:
		return string
	left = []
	right = []
	for i in range(0, len(string)):
		if i < len(string) / 2:
			left.append(string[i])
		else:
			right.append(string[i])
	left = merge_sort(left)
	right = merge_sort(right)
	return merge(left, right)

def merge(left, right):
	sol = []
	while len(left) > 0 and len(right) > 0:
		if left[0] < right[0]:
			sol.append(left[0])
			left = left[1:]
		else:
			sol.append(right[0])
			right = right[1:]
	while len(left) > 0:
		sol.append(left[0])
		left = left[1:]
	while len(right) > 0:
		sol.append(right[0])
		right = right[1:]
	return sol
(n, k) = map(int, input().strip().split())
string = list(map(int, input().strip().split()))
sort = merge_sort(string)
diffmin = 1001
for i in range(0, len(sort) - n + 1):
	diff = sort[i + n - 1] - sort[i]
	if diff < diffmin:
		diffmin = diff
print(diffmin)


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


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
b = 1000000000
for i in range(m - n + 1):
	k = int(a[i + n - 1]) - int(a[i])
	if k < b:
		b = k
	else:
		continue
print(b)


(n, m) = map(int, input().split())
p = sorted(list(map(int, input().split())))
i = 1
mn = max(p[0:n]) - min(p[0:n])
while i <= m - n:
	d = max(p[i:i + n]) - min(p[i:i + n])
	if d < mn:
		mn = d
	i += 1
print(mn)


min_val = 1000000000
(index, _) = [int(a) for a in input().split()]
list_puzz = sorted([int(a) for a in input().split()])
for thing in range(index - 1, len(list_puzz)):
	test = list_puzz[thing] - list_puzz[thing - index + 1]
	if min_val > test:
		min_val = test
print(min_val)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
mo = 9999999999
for i in range(m - n + 1):
	mo = min(abs(a[i] - a[n - 1 + i]), mo)
print(mo)


[n, m] = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
arr = sorted(arr)
minele = 1001
i = 0
while i + n - 1 < m:
	minele = min(minele, arr[i + n - 1] - arr[i])
	i += 1
print(minele)


n_m = [int(i) for i in input().split(' ')]
(n, m) = (n_m[0], n_m[1])
puzzle_sizes = [int(i) for i in input().split(' ')]
puzzle_sizes.sort()
differences = []
for i in range(len(puzzle_sizes) - n + 1):
	differences.append(abs(puzzle_sizes[i] - puzzle_sizes[i + n - 1]))
print(min(differences))


(m, n) = map(int, input().split())
lis = list(map(int, input().split()))
lis.sort()
dif = 999999999999999999
for i in range(0, len(lis) - m + 1):
	num = lis[m - 1 + i] - lis[i]
	dif = min(dif, num)
print(dif)


param = input().split(' ')
stu = int(param[0])
puz = int(param[1])
piecesl = input().split()
pieces = [int(i) for i in piecesl]
sor = sorted(pieces)
diff = sor[stu - 1] - sor[0]
for i in range(1, len(sor) - stu + 1):
	dif2 = sor[stu + i - 1] - sor[i]
	diff = min(dif2, diff)
print(diff)


(n, m) = [int(x) for x in input().split()]
puzzle = [int(x) for x in input().split()]
puzzle.sort()
minimun = float('Inf')
index = 0
upper_index = n
while upper_index <= m:
	subset = puzzle[index:upper_index]
	value = max(subset) - min(subset)
	if value < minimun:
		minimun = value
	index += 1
	upper_index += 1
print(minimun)


(n, m) = input().split()
n = int(n)
m = int(m)
l = input().split()
for i in range(m):
	l[i] = int(l[i])
l.sort()
min1 = l[m - 1] - l[0]
for i in range(m - n + 1):
	min1 = min(min1, l[i + n - 1] - l[i])
print(min1)


(n, nP) = map(int, input().split())
puzzles = list(map(int, input().split()))
i = 0
smallest = 100000000000000000
puzzles.sort()
for i in range(nP):
	try:
		answer = puzzles[i + n - 1] - puzzles[i]
		if smallest > answer:
			smallest = answer
	except:
		break
print(smallest)


(n, m) = map(int, input().split())
A = [int(x) for x in input().split()]
A.sort()
Ans = []
for i in range(0, m - n + 1):
	B = A[i:i + n]
	Ans.append(B[-1] - B[0])
print(min(Ans))


def Max(vect, size):
	maximum = vect[0]
	for i in range(size):
		if vect[i] >= maximum:
			maximum = vect[i]
	return maximum

def Min(vect, size):
	minimum = vect[0]
	for i in range(size):
		if vect[i] <= minimum:
			minimum = vect[i]
	return minimum
while True:
	(n, m) = map(int, input().split(' '))
	if n >= 2 and n <= m and (m <= 50):
		break
f = input().split(' ')
liste = []
for i in range(m):
	liste.append(int(f[i]))
liste = sorted(liste)
i = 0
j = n
res = []
while j <= m:
	val = Max(liste[i:j], j - i) - Min(liste[i:j], j - i)
	res.append(val)
	i += 1
	j += 1
print(Min(res, m - n + 1))


3
import sys
(n, m) = list(map(int, sys.stdin.readline().strip().split()))
pieces = list(map(int, sys.stdin.readline().strip().split()))
pieces.sort()
diff = []
for i in range(0, m - n + 1):
	diff.append(pieces[i + n - 1] - pieces[i])
print(min(diff))


def main():
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	mn = arr[n - 1] - arr[0]
	for i in range(n, len(arr)):
		temp = arr[i] - arr[i - n + 1]
		if temp < mn:
			mn = temp
	print(mn)
main()


import sys

class Scanner:

	def __init__(self):
		self.current_tokens = []

	def remaining_tokens(self):
		return len(self.current_tokens)

	def nextline(self):
		assert self.remaining_tokens() == 0, 'Reading next line with remaining tokens'
		return input()

	def nexttokens(self):
		return self.nextline().split()

	def nexttoken(self):
		if len(self.current_tokens) == 0:
			self.current_tokens = self.nexttokens()
		assert self.remaining_tokens() > 0, 'Not enough tokens to parse.'
		return self.current_tokens.pop(0)

	def nextints(self, n=-1):
		if n == -1:
			return list(map(int, self.nexttokens()))
		else:
			return (self.nextint() for i in range(n))

	def nextint(self):
		return int(self.nexttoken())

def quit():
	sys.exit(0)
stdin = Scanner()
nextint = stdin.nextint
nextints = stdin.nextints
nextline = stdin.nextline
(n, m) = nextints(2)
f = nextints()
f = sorted(f)
d = 1000000
for i in range(0, m - n + 1):
	d = min(d, f[i + n - 1] - f[i])
print(d)


(n, m) = map(int, input().split())
t = list(map(int, input().split()))
t = sorted(t)
ans = 99999999
for i in range(m - n + 1):
	d = t[i + n - 1] - t[i]
	ans = min(ans, d)
print(ans)


(a, b) = map(int, input().split())
s = list(map(int, input().split()))
s = sorted(s)
d = 0
m = s[a - 1] - s[0]
for i in range(b - a + 1):
	d = s[i + a - 1] - s[i]
	if d < m:
		m = d
print(m)


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


(n, m) = map(int, input().split())
if m >= n and n >= 2 and (m <= 50):
	x = list(map(int, input().split()))
	x.sort()
	min = x[n - 1] - x[0]
	for i in range(m - n + 1):
		c = x[n - 1] - x[i]
		n += 1
		if c <= min:
			min = c
	print(min)


(a, b) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
an = l[a - 1] - l[0]
for i in range(1, b - a + 1):
	an = min(l[i + a - 1] - l[i], an)
print(an)


(l, n) = map(int, input().rstrip().split())
plist = list(map(int, input().rstrip().split()))
plist.sort()
minval = max(plist)
for i in range(0, n - l + 1):
	val = plist[i + l - 1] - plist[i]
	if val < minval:
		minval = val
print(minval)


words = input().split()
n = int(words[0])
m = int(words[1])
f = list(map(int, input().split()))
f.sort()
res = 999999
for i in range(len(f) - n + 1):
	if f[i + n - 1] - f[i] < res:
		res = f[i + n - 1] - f[i]
print(res)


(n, m) = list(map(int, input().split()))
pazl = list(map(int, input().split()))
pazl.sort()
minimum = sum(pazl)
for i in range(0, m - n + 1):
	minimum = min(minimum, pazl[i + n - 1] - pazl[i])
print(minimum)


(chs, tot) = [int(x) for x in input().split()]
puzz = [int(y) for y in input().split()]
puzz.sort()
m = 0
if chs == tot:
	print(puzz[tot - 1] - puzz[0])
else:
	for i in range(tot - chs + 1):
		if i == 0:
			m = puzz[chs - 1] - puzz[0]
		elif m >= puzz[i + chs - 1] - puzz[i]:
			m = puzz[i + chs - 1] - puzz[i]
	print(m)


(n, m) = [int(i) for i in input().split()]
li = input().split()
line = []
for l in li:
	line.append(int(l))
line.sort()
line.reverse()
if n == m:
	print(abs(line[0] - line[n - 1]))
else:
	minus = []
	for i in range(m - n + 1):
		minus.append(line[i] - line[i + n - 1])
	print(min(minus))


(n, m) = (int(x) for x in input().split(' '))
f = [int(x) for x in input().split(' ')]
f.sort()
minDiff = 9999
for i in range(m - n + 1):
	minDiff = min(f[i + n - 1] - f[i], minDiff)
print(minDiff)


(n, m) = [int(s) for s in input().split(' ')]
f = [int(s) for s in input().split(' ')]
f.sort()
min_diff = float('inf')
for i in range(m - n + 1):
	min_diff = min(f[i + n - 1] - f[i], min_diff)
print(min_diff)


[n, m] = [int(i) for i in input().split(' ')]
f = sorted([int(i) for i in input().split(' ')])
d = [0]
for i in range(1, m):
	d += [f[i] - f[i - 1]]
s = [9999] * (n - 1)
for i in range(n - 1, m):
	s += [sum(d[i - n + 2:i + 1])]
print(min(s))


(n, m) = [int(i) for i in input().split()]
f = [int(i) for i in input().split()]
f.sort()
c = f[n - 1] - f[0]
for i in range(m - n + 1):
	if f[n + i - 1] - f[i] < c:
		c = f[n + i - 1] - f[i]
print(c)


T = input().split()
n = int(T[0])
m = int(T[1])
puzzles_char = input().split()
puzzles = [int(x) for x in puzzles_char]
puzzles.sort()
diff = 10000000000
for i in range(m - n + 1):
	if puzzles[i + n - 1] - puzzles[i] < diff:
		diff = puzzles[i + n - 1] - puzzles[i]
print(diff)


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
f.sort()
minimum = 99999
for i in range(m - n + 1):
	dif = f[i + n - 1] - f[i]
	if dif < minimum:
		minimum = dif
print(minimum)


(kids, puzzles) = input().split()
kids = int(kids)
puzzles = int(puzzles)
tab = [int(x) for x in input().split()]
tab = sorted(tab)
i = 0
res = 9999
while i < puzzles:
	if i + kids - 1 < puzzles:
		res = min(res, tab[i + kids - 1] - tab[i])
	i += 1
print(res)


(n, m) = list(map(int, input().split()))
L = list(map(int, input().split()))
df = 10000
L = sorted(L)
for i in range(n - 1, m):
	df = min(L[i] - L[i - n + 1], df)
print(df)


(n, m) = map(int, input().split())
a = [int(x) for x in input().split()]
a.sort()
mi = 1001
i = 0
while i <= m - n:
	mi = min(mi, a[i + n - 1] - a[i])
	i += 1
print(mi)


line = input().split(' ')
n = int(line[0])
m = int(line[1])
line = input().split(' ')
for i in range(len(line)):
	line[i] = int(line[i])
line.sort()
diffs = []
for sn in range(0, len(line) - n + 1, 1):
	a = line[sn + (n - 1)]
	b = line[sn]
	diff = a - b
	diffs.append(diff)
print(min(diffs))


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
f.sort()
res = 1000
for i in range(m - n + 1):
	res = min(f[i + n - 1] - f[i], res)
print(res)


S = input().split()
a = int(S[0])
b = int(S[1])
l = list(map(int, input().split()))
l.sort()
l.reverse()
me = 10000000
for i in range(b - a + 1):
	if l[i] - l[i + a - 1] <= me:
		me = l[i] - l[i + a - 1]
print(me)


(Children, Puzzles) = input().split()
Children = int(Children)
Puzzles = int(Puzzles)
Puzzle = input().split(maxsplit=Puzzles - 1)
for i in range(Puzzles):
	Puzzle[i] = int(Puzzle[i])
Puzzle.sort()
poz = 1
Result = Puzzle[Children - 1] - Puzzle[0]
while poz < Puzzles - Children + 1:
	Local = Puzzle[poz + Children - 1] - Puzzle[poz]
	Result = min(Local, Result)
	poz += 1
print(Result)


s = input().split()
s[0] = int(s[0])
a = input().split()
for i in range(len(a)):
	a[i] = int(a[i])
a.sort()
min = a[s[0] - 1] - a[0]
ans = a[s[0] - 1] - a[0]
for i in range(s[0], len(a)):
	if a[i] - a[i - s[0] + 1] < min:
		min = a[i] - a[i - s[0] + 1]
		ans = min
print(ans)


(n, m) = [int(i) for i in input().split(' ')]
sizes = sorted([int(i) for i in input().split(' ')])
minim = sizes[n - 1] - sizes[0]
for poz in range(1, m - n + 1):
	if sizes[poz + n - 1] - sizes[poz] < minim:
		minim = sizes[poz + n - 1] - sizes[poz]
print(minim)


(n, m) = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = []
c = []
for i in range(0, m):
	b += a[i:i + n]
	if b != [] and len(b) == n:
		c.append(max(b) - min(b))
	b = []
b = a[m - n:]
c.append(max(b) - min(b))
print(min(c))


(n, m) = map(int, input().split())
nums = input().split(' ')
nums_int = [int(n) for n in nums]
nums_int.sort()
diff = nums_int[-1] - nums_int[0]
for i in range(m - n + 1):
	current_diff = nums_int[i + n - 1] - nums_int[i]
	if current_diff < diff:
		diff = current_diff
print(diff)


(a, b) = map(int, input().split())
pieces = sorted(list(map(int, input().split())))
differences = []
for x in range(b - a + 1):
	differences.append(pieces[x + a - 1] - pieces[x])
print(min(differences))


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


(n, m) = input().split()
n = int(n)
m = int(m)
x = input()
a = x.split()
for i in range(0, len(a)):
	a[i] = int(a[i])
a = sorted(a)
b = []
for j in range(0, len(a) - n + 1, 1):
	k = a[j + n - 1] - a[j]
	b.append(k)
print(min(b))


import sys
import math
inf = 5000000
(n, m) = [int(e) for e in input().split()]
a = [int(e) for e in input().split()]
for i in range(m - 1):
	for j in range(i + 1, m):
		if a[i] > a[j]:
			t = a[i]
			a[i] = a[j]
			a[j] = t
r = inf
for i in range(m):
	if i + n - 1 >= m:
		break
	r = min(r, a[i + n - 1] - a[i])
print(r)


def Merge(a, lo, hi):
	temp = []
	k = 0
	m = (lo + hi) // 2
	p1 = lo
	p2 = m + 1
	while p1 <= m and p2 <= hi:
		if a[p1] > a[p2]:
			temp.append(a[p2])
			p2 = p2 + 1
		else:
			temp.append(a[p1])
			p1 = p1 + 1
		k = k + 1
	while p1 <= m:
		temp.append(a[p1])
		p1 = p1 + 1
		k = k + 1
	while p2 <= hi:
		temp.append(a[p2])
		p2 = p2 + 1
		k = k + 1
	for i in range(k):
		a[lo + i] = temp[i]
	return a

def MS(a, lo, hi):
	if lo == hi:
		return
	m = (lo + hi) // 2
	MS(a, lo, m)
	MS(a, m + 1, hi)
	Merge(a, lo, hi)
	return a
(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
a = MS(a, 0, m - 1)
ans = 100000000
for i in range(m - n + 1):
	ans = min(ans, a[i + n - 1] - a[i])
print(ans)


import sys
li = [int(i) for i in input().split()]
k = li[0]
n = li[1]
li1 = [int(i) for i in input().split()]
li1.sort()
mini = sys.maxsize
i = 0
while i + k - 1 < n:
	mini = min(mini, abs(li1[i] - li1[i + k - 1]))
	i += 1
print(mini)


n = tuple(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
q = []
for i in range(n[1] - n[0] + 1):
	if len(q) == 0:
		q += [a[i + n[0] - 1] - a[i]]
	elif a[i + n[0] - 1] - a[i] < min(q):
		q += [a[i + n[0] - 1] - a[i]]
print(min(q))


(n, m) = map(int, input().split())
puzzle = [int(x) for x in input().split()]
puzzle = sorted(puzzle)
d = puzzle[n - 1] - puzzle[0]
for i in range(1, m - n + 1):
	D = puzzle[i + n - 1] - puzzle[i]
	d = min(d, D)
print(d)


s = [int(i) for i in input().split()]
ss = [int(i) for i in input().split()]
ss.sort()
diff = s[1] - s[0]
less = abs(ss[0] - ss[s[0] - 1])
for i in range(diff + 1):
	check = abs(ss[i] - ss[s[0] - 1 + i])
	if check < less:
		less = check
print(less)


line = input()
(n, m) = [int(i) for i in line.split()]
line = input()
puzzles = [int(i) for i in line.split()]
puzzles.sort()
c = max(puzzles)
for i in range(m - n + 1):
	c = min(c, puzzles[i + n - 1] - puzzles[i])
print(c)


(s, n) = map(int, input().split())
puzzles = list(map(int, input().split()))
puzzles.sort()
i = 0 + s
distinct = 10000
while i <= n:
	if distinct > puzzles[i - 1] - puzzles[i - s]:
		distinct = min(distinct, puzzles[i - 1] - puzzles[i - s])
		i += 1
	else:
		i += 1
print(distinct)


(n, m) = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
diff = p[-1]
it = 0
while it <= m - n:
	if p[it + n - 1] - p[it] < diff:
		diff = p[it + n - 1] - p[it]
	it += 1
print(diff)


(N, M) = map(int, input().split())
sortedArray = sorted(list(map(int, input().split())))
sol = []
for i in range(M - N + 1):
	sol.append(sortedArray[N - 1 + i] - sortedArray[i])
print(min(sol))


num = input().split()
n = int(num[0])
m = int(num[1])
f = [int(i) for i in input().split()]
f.sort()
res = 1000
for i in range(m - n + 1):
	minus = f[i + n - 1] - f[i]
	if res > minus:
		res = minus
print(res)


x = input()
(n, m) = (int(x.split()[0]), int(x.split()[1]))
y = input()
z = y.split()
for i in range(len(z)):
	z[i] = int(z[i])
z.sort()
diff = [0 for i in range(n - 1, m)]
for i in range(n - 1, m):
	diff[i - n + 1] = z[i] - z[i - n + 1]
print(min(diff))


(n, m) = map(int, input().strip().split())
a = list(map(int, input().split()))
a.sort()
b = []
c = []
start = 0
end = n - 1
while end < m:
	b.append([a[end] - a[start], start, end])
	c.append(a[end] - a[start])
	start += 1
	end += 1
print(min(c))


(n, m) = map(int, input().split())
ls = sorted(list(map(int, input().split())))
i = 0
l = []
c = []
while True:
	l.append(ls[i:n + i])
	if n + i == len(ls):
		break
	i += 1
for val in l:
	c.append(max(val) - min(val))
print(min(c))


(n, m) = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
l.sort()
best = l[-1] - l[0]
for i in range(len(l) - n + 1):
	cur = l[i + n - 1] - l[i]
	if cur < best:
		best = cur
print(best)


(k, n) = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
result = 10001
for i in range(0, n - k + 1):
	result = int(min(result, a[i + k - 1] - a[i]))
print(result)


(n, m) = map(int, input().split())
puzzles = sorted(map(int, input().split()))
diff = n - 1
min_pair = min(zip(puzzles[:-diff], puzzles[diff:]), key=lambda a: a[1] - a[0])
print(min_pair[1] - min_pair[0])


(student, puzzle) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
min = l[student - 1] - l[0]
for i in range(puzzle - student + 1):
	if l[student - 1 + i] - l[i] < min:
		min = l[student - 1 + i] - l[i]
print(min)


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


import math
from collections import defaultdict, Counter, deque
INF = float('inf')

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def vars():
	return map(int, input().split())

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

def main():
	(n, m) = vars()
	arr = array()
	arr.sort()
	l = 0
	r = n - 1
	diff = INF
	while r < m:
		if arr[r] - arr[l] < diff:
			diff = arr[r] - arr[l]
		l += 1
		r += 1
	print(diff)
t = 1
for _ in range(t):
	main()


def main():
	inp = input().split()
	(n, m) = (int(inp[0]), int(inp[1]))
	inp2 = input().split()
	L = []
	Min = 1000
	for i in inp2:
		L.append(int(i))
	L.sort(reverse=True)
	for i in range(m - n + 1):
		Min = min(Min, L[i] - L[i + n - 1])
	print(Min)
main()


n = list(map(int, input().split()))
s = list(map(int, input().split()))
s.sort()
min1 = s[n[0] - 1] - s[0]
for i in range(n[1] - (n[0] - 1)):
	if min1 > s[i + n[0] - 1] - s[i]:
		min1 = s[i + n[0] - 1] - s[i]
print(min1)


(n, m) = map(int, input().split())
puzzle = list(map(int, input().split()))
puzzle.sort()
minimum = 1001
for i in range(len(puzzle) - n + 1):
	minimum = min(minimum, puzzle[i + n - 1] - puzzle[i])
print(minimum)


s = input(' ')
(n, m) = s.split(' ')
n = int(n)
m = int(m)
s1 = input('')
list = s1.split(' ')
list1 = []
for i in range(len(list)):
	list1.append(int(list[i]))
list1.sort()
list2 = []
j = 0
while j + n - 1 < m:
	min1 = list1[j + n - 1] - list1[j]
	list2.append(min1)
	j += 1
print(min(list2))


a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sorted(b)
d = 1000
for r in range(0, len(b) - a[0] + 1):
	f = c[r:r + a[0]]
	m = max(f) - min(f)
	if m <= d:
		d = m
print(d)


(a, b) = input().split()
(a, b) = (int(a), int(b))
s = input()
list = s.split()
for i in range(len(list)):
	list[i] = int(list[i])
list = sorted(list)
minr = 10000000
for i in range(len(list) - a + 1):
	if abs(list[i] - list[i + a - 1]) < minr:
		minr = abs(list[i] - list[i + a - 1])
print(minr)


(n, m) = input().split()
n = int(n)
m = int(m)
l = list(map(int, input().split()))
l.sort()
res = []
for i in range(len(l)):
	a = []
	a = l[i:i + n]
	if len(a) == n:
		res.append(max(a) - min(a))
print(min(res))


(n, m) = input().split()
f = input()
f = [int(x) for x in f.split()]
if int(n) == int(m):
	print(max(f) - min(f))
else:
	dup = sorted(f)
	start = 0
	end = int(n) - 1
	ans = []
	while end < int(m):
		dif = dup[end] - dup[start]
		ans.append(dif)
		start += 1
		end += 1
	print(min(ans))


(n, m) = map(int, input().split())
l = sorted(list(map(int, input().split())))
r = []
for i in range(len(l) - 1):
	r.append(l[i + 1] - l[i])
o = []
for i in range(m - n + 1):
	o.append(sum(r[i:i + n - 1]))
print(min(o))


(n, m) = list(map(int, input().split()))
f = list(map(int, input().split()))
f.sort()
best = 1000
if len(f) == 2:
	print(f[1] - f[0])
	exit()
else:
	for i in range(m - n + 1):
		best = min(best, f[i + n - 1] - f[i])
print(best)


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


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
min_ = 9999
if m == n:
	print(a[-1] - a[0])
else:
	for i in range(0, m - n + 1):
		if abs(a[i + n - 1] - a[i]) < min_:
			min_ = abs(a[i + n - 1] - a[i])
	print(min_)


x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
y.sort()
t = y[len(y) - 1]
for i in range(x[1] - x[0] + 1):
	if t > y[i + x[0] - 1] - y[i]:
		t = y[i + x[0] - 1] - y[i]
print(t)


(n, m) = map(int, input().split(' '))
nums = sorted(map(int, input().split(' ')))
max_num = nums[n - 1] - nums[0]
for i in range(m - n + 1):
	max_num = min(max_num, nums[i + n - 1] - nums[i])
print(max_num)


k = []
res = 0
(a, b) = (int(x) for x in input().split())
l = sorted(list(map(int, input().split())))
try:
	for i in range(len(l)):
		res = l[i + a - 1] - l[i]
		k.append(res)
		miin = min(k)
except IndexError:
	print(miin)


(n, m) = [int(i) for i in input().split()]
Fm = [int(i) for i in input().split()]
var = 1001
Fm.sort()
for i in range(n - 1, m):
	var = min(var, Fm[i] - Fm[i - n + 1])
print(var)


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
I = sys.stdin.readline

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def mi():
	return map(int, I().strip().split())

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def valid(row, col, rows, cols, rcross, lcross):
	return rows[row] == 0 and cols[col] == 0 and (rcross[col + row] == 0) and (lcross[col - row] == 0)

def div(n):
	tmp = []
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			cnt = 0
			while n % i == 0:
				n = n // i
				cnt += 1
			tmp.append((i, cnt))
	if n > 1:
		tmp.append((n, 1))
	return tmp

def isPrime(n):
	if n <= 1:
		return False
	elif n <= 2:
		return True
	else:
		flag = True
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				flag = False
				break
		return flag

def s(b):
	ans = []
	while b > 0:
		tmp = b % 10
		ans.append(tmp)
		b = b // 10
	return ans

def main():
	(n, m) = mi()
	arr = sorted(li())
	i = 0
	j = n - 1
	ans = 10000
	while j < m:
		ans = min(ans, arr[j] - arr[i])
		i += 1
		j += 1
	print(ans)
main()


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


(n, m) = map(int, input().split())
ar = list(map(int, input().split()))
ar.sort()
mi = sum(ar)
for x in range(m - n + 1):
	if ar[x + n - 1] - ar[x] < mi:
		mi = ar[x + n - 1] - ar[x]
print(mi)


(x, p) = map(int, input().split(' '))
l = list(map(int, input().split(' ')))
l.sort()
i = []
for k in range(1, p):
	i.append(l[k] - l[k - 1])
sum1 = sum(i)
for k in range(p - x + 1):
	c = 0
	for t in range(x - 1):
		c = c + i[k + t]
	if sum1 > c:
		sum1 = c
print(sum1)


(n, m) = list(map(int, input().split()))
t = list(map(int, input().split()))
t.sort()
s = t[n - 1] - t[0]
for k in range(m - n + 1):
	p = t[k + n - 1] - t[k]
	if p < s:
		s = p
print(s)


from sys import stdin, stdout
(n, m) = map(int, stdin.readline().split())
arr = list(map(int, stdin.readline().split()))
m = 1001
arr.sort()
for i in range(len(arr), -1, -1):
	for j in range(i):
		if len(arr[j:i]) == n:
			A = max(arr[j:i])
			B = min(arr[j:i])
			m = min(A - B, m)
stdout.write(str(m) + '\n')


(n, m) = input().split()
n = int(n)
m = int(m)
a = [int(val) for val in input().split()]
a.sort()
ans = a[m - 1] - a[0]
for i in range(m - n + 1):
	ans = min(ans, a[i + n - 1] - a[i])
print(ans)


(n, m) = [int(x) for x in input().split()]
puzzles = [int(x) for x in input().split()]
puzzles.sort()
a = puzzles[n - 1] - puzzles[0]
for i in range(1, m - n + 1):
	A = puzzles[i + n - 1] - puzzles[i]
	a = min(a, A)
print(a)


import sys

def solver(a, b):
	newList = sorted(b, reverse=True)
	answer = 10000
	location = a - 1
	for x in range(len(newList) - a + 1):
		calculator = newList[x] - newList[location]
		if calculator < answer:
			answer = calculator
		location = location + 1
	return answer

def main():
	lines = sys.stdin.readlines()
	b = list(map(int, lines[0].split()))
	print(solver(b[0], list(map(int, lines[1].split()))))
main()


shabi = str(input()).split(' ')
n = int(shabi[0])
m = int(shabi[1])
puzzle = str(input()).split(' ')
quantity = []
i = 0
while i < m:
	quantity.append(int(puzzle[i]))
	i = i + 1
quantity.sort()
i = 0
j = 1001
while i + n - 1 < m:
	k = quantity[i + n - 1] - quantity[i]
	if k < j:
		j = k
		i = i + 1
	else:
		i = i + 1
print(str(j))


(n, m) = [int(x) for x in input().split()]
fs = sorted([int(x) for x in input().split()])
high = n - 1
best = fs[high] - fs[0]
for i in range(1, m - n + 1):
	diff = fs[i + high] - fs[i]
	best = min(diff, best)
print(best)


d = input().split(' ')
n = int(d[0]) - 1
m = int(d[1])
count = 1000000
jigsaws = sorted([int(i) for i in input().split(' ')])
for i in range(m - n):
	if jigsaws[i + n] - jigsaws[i] < count:
		count = jigsaws[i + n] - jigsaws[i]
print(count)


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


ss = lambda : input()
si = lambda : int(input())
(n, m) = map(int, input().split())
f = sorted(map(int, input().split()))
best = 1 << 30
for i in range(m - n + 1):
	best = min(best, f[i + n - 1] - f[i])
print(best)


(a, b) = [int(x) for x in input().split()]
s = [int(x) for x in input().split()]
s.sort()
d = s[a - 1] - s[0]
for i in range(b - a + 1):
	d = min(d, s[a + i - 1] - s[i])
print(d)


import math
st = ''

def func(n, k, l1):
	m = 1000
	l1.sort()
	for i in range(0, k - n + 1):
		m = min(m, l1[i + n - 1] - l1[i])
	return m
for _ in range(1):
	(n, k) = map(int, input().split())
	l1 = list(map(int, input().split()))
	st += str(func(n, k, l1)) + '\n'
print(st)


(n, m) = map(int, input().split())
f = [int(i) for i in input().split()]
f.sort()
diff = max(f) - min(f)
for i in range(m - n + 1):
	if f[i + n - 1] - f[i] < diff:
		diff = f[i + n - 1] - f[i]
	else:
		continue
print(diff)


(n, m) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.sort()
mm = 1000
for i in range(m - n + 1):
	mm = min(mm, a[i + n - 1] - a[i])
print(mm)


(n, m) = map(int, input().split())
l = [*map(int, input().split())]
l.sort()
a = l[n - 1] - l[0]
y = 1
while y <= m - n:
	if l[n - 1 + y] - l[y] < a:
		a = l[n - 1 + y] - l[y]
	y += 1
print(a)


(n, m) = [int(x) for x in input().split()]
nums = [int(x) for x in input().split()]
nums.sort()
sums = []
for i in range(m - n + 1):
	sums.append(nums[n - 1 + i] - nums[i])
print(min(sums))


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


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	(n, m) = mi()
	a = li()
	a.sort()
	mx = inf
	for i in range(m - n + 1):
		mx = min(a[i + n - 1] - a[i], mx)
	print(mx)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, m) = map(int, input().split())
array = list(map(int, input().split()))
array.sort()
diff = 999999999999
min_index = 0
max_index = 0
for i in range(m - n + 1):
	if array[i + n - 1] - array[i] < diff:
		min_inde = i
		max_index = i + n - 1
		diff = array[i + n - 1] - array[i]
print(diff)


(n, m) = [int(x) for x in input().split()]
quant = [int(x) for x in input().split()]
q = sorted(quant)
diff = q[n - 1] - q[0]
for i in range(1, m - n + 1):
	diff = min(q[i + n - 1] - q[i], diff)
print(diff)


(a, b) = map(int, input().split())
c = list(map(int, input().split()))
c.sort(reverse=True)
d = []
if a == b:
	print(c[0] - c[b - 1])
else:
	for i in range(b - a + 1):
		e = c[i] - c[i + a - 1]
		d.append(e)
	d.sort()
	print(d[0])


from sys import stdin
(n, m) = map(int, input().split())
nb = list(map(int, input().split()))
nb.sort()
minDiff = nb[m - 1]
for i in range(n - 1, m):
	minDiff = min(minDiff, nb[i] - nb[i - n + 1])
print(minDiff)


import math
from itertools import combinations
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = a[:]
a.sort()
best = math.inf
for i in range(m - n + 1):
	c = a[i:n + i]
	best = min(best, max(c) - min(c))
print(best)


(n, m) = map(int, input().split())
ls = sorted(list(map(int, input().split())))
another = []
for i in range(m - n + 1):
	another.append(ls[i + n - 1] - ls[i])
print(min(another))


(s, k) = map(int, input().split())
L = list(map(int, input().split()))
L.sort()
print(min((L[i + s - 1] - L[i] for i in range(k - s + 1))))


(n, m) = [int(x) for x in input().split()]
f = sorted([int(x) for x in input().split()])
res = 10 ** 8
for i in range(m - n + 1):
	res = min(res, f[n + i - 1] - f[i])
print(res)


(n, m) = map(int, input().strip().split())
puzzles = list(map(int, input().strip().split()))
puzzles.sort()
res = 9999999
for i in range(0, m - n + 1):
	res = min(puzzles[i + n - 1] - puzzles[i], res)
print(res)


def solve(n, m, arr):
	return min(map(lambda i: arr[n - 1 + i] - arr[i], range(m - n + 1)))
inp = list(map(int, input().split()))
arr = sorted(list(map(int, input().split())))
print(solve(inp[0], inp[1], arr))


(n, m) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
a.sort()
mini = 100000
for i in range(0, m - n + 1):
	x = max(a[i:i + n]) - min(a[i:i + n])
	if x < mini:
		mini = x
print(mini)


def main():
	(k, n) = list(map(int, input().split()))
	a = sorted(list(map(int, input().split())))
	(i, j) = (0, k - 1)
	minI = 10000000000.0
	while j < n:
		if a[j] - a[i] < minI:
			minI = a[j] - a[i]
		i += 1
		j += 1
	print(minI)
main()


import sys
(m, n) = map(int, input().split())
a = list(map(int, input().split()))
ai = sorted(a)
print(min((j - i for (i, j) in zip(ai, ai[m - 1:]))))


(n, m) = map(int, input().split())
f = [int(x) for x in input().split()]
s = sorted(f)
cha = s[m - 1] - s[0]
for i in range(m - n + 1):
	if s[i + n - 1] - s[i] < cha:
		cha = s[i + n - 1] - s[i]
print(cha)


(n, m) = map(int, input().split())
F = list(map(int, input().split()))
F.sort()
ans = 1000
for i in range(len(F) - n + 1):
	ans = min(ans, F[i + n - 1] - F[i])
print(ans)


tmp = input()
tmp = tmp.split(' ')
n = int(tmp[0])
m = int(tmp[1])
tmp = input()
tmp = tmp.split(' ')
arr = []
for i in range(0, m):
	arr.append(0)
for i in range(0, m):
	arr[i] = int(tmp[i])
arr.sort()
ans = arr[len(arr) - 1] - arr[0]
for i in range(0, m - n + 1):
	temp = arr[i + n - 1] - arr[i]
	if temp < ans:
		ans = temp
print(ans)


def parser():
	while 1:
		data = list(input().split(' '))
		for number in data:
			if len(number) > 0:
				yield number
input_parser = parser()

def get_word():
	global input_parser
	return next(input_parser)

def get_number():
	data = get_word()
	try:
		return int(data)
	except ValueError:
		return float(data)
n = get_number()
m = get_number()
f = []
for i in range(m):
	f.append(get_number())
f.sort()
minDif = f[-1] - f[0]
i = 0
while i + n - 1 < m:
	minDif = min(minDif, f[i + n - 1] - f[i])
	i += 1
print(minDif)


(n, m) = map(int, input().split())
lst = list(map(int, input().split()))
lst.sort()
mini = 1001
if m == n:
	print(lst[-1] - lst[0])
else:
	for i in range(m - n + 1):
		temp = lst[i + n - 1] - lst[i]
		if temp < mini:
			mini = temp
	print(mini)


n = input().split(' ')
s1 = input().split(' ')
s = []
for i in range(0, len(s1)):
	s.append(int(s1[i]))
a = sorted(s)
m = a[len(s) - 1] - a[0]
for i in range(0, len(a) - int(n[0]) + 1):
	a1 = a[i:i + int(n[0])]
	m1 = a1[int(n[0]) - 1] - a1[0]
	if m1 < m:
		m = m1
print(m)


(n, m) = map(int, input().split())
t = input()
a = [int(i) for i in t.split()]
a.sort()
tk = a[n - 1] - a[0]
i = 1
while i < m - n + 1:
	if a[i + n - 1] - a[i] < tk:
		tk = a[i + n - 1] - a[i]
	i += 1
print(tk)


(n, m) = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
a.sort()
min_gap = float('inf')
for i in range(0, len(a) - n + 1):
	min_gap = min(min_gap, a[i + n - 1] - a[i])
print(min_gap)


word1 = input().split(' ')
word2 = input().split(' ')
n = int(word1[0])
m = int(word1[1])
arr = []
for i in range(m):
	arr.append(int(word2[i]))
arr.sort()
k = arr[n - 1] - arr[0]
for i in range(m - n + 1):
	if arr[i + n - 1] - arr[i] < k:
		k = arr[i + n - 1] - arr[i]
print(k)


def integerize(arr):
	for i in range(len(arr)):
		arr[i] = int(arr[i])
	return arr
(n, m) = input().split()
n = int(n)
m = int(m)
arr = input().split()
arr = integerize(arr)
arr.sort()
i = 1
min_diff = arr[n - 1] - arr[0]
while i + n - 1 < m:
	diff = arr[i + n - 1] - arr[i]
	if diff < min_diff:
		min_diff = diff
	i += 1
print(min_diff)


(n, m) = [int(i) for i in input().split()]
sizes = [int(i) for i in input().split()]
sizes.sort()
i = m - 1
min_diff = sizes[m - 1]
for i in range(0, m - n + 1):
	min_diff = min(min_diff, sizes[i + n - 1] - sizes[i])
print(min_diff)


(a, b) = map(int, input().split())
pazzles = sorted([int(i) for i in input().split()])
minn = pazzles[-1]
for i in range(0, b - a + 1):
	if pazzles[i + a - 1] - pazzles[i] < minn:
		minn = pazzles[i + a - 1] - pazzles[i]
print(minn)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
a = l[-1] - l[0]
k = m - n
i = 0
while i < m + 1 - n:
	b = l[i + n - 1] - l[i]
	if b < a:
		a = b
	i += 1
print(a)


def countIt(mi, ma, l):
	return sum([1 for x in l if x >= mi and x <= ma])

def findMinGap(l, t):
	result = []
	for i in range(len(l)):
		for j in range(i + 1, len(l)):
			if countIt(l[i] if l[i] < l[j] else l[j], l[i] if l[i] > l[j] else l[j], l) >= t:
				result.append(abs(l[i] - l[j]))
	return min(result)
ab = [int(x) for x in input().split()]
data = [int(x) for x in input().split()]
print(findMinGap(data, ab[0]))


(n, m) = input().split()
j = sorted(list(map(int, input().split()[:int(m)])))
x = int(m) - int(n) + 1
diff = []
for i in range(x):
	z = i + 1 - x
	if z == 0:
		J = j[i:]
	else:
		J = j[i:z]
	diff.append(max(J) - min(J))
print(min(diff))


def rng(lis):
	return lis[-1] - lis[0]
(n, m) = map(int, input().split())
lis = [int(x) for x in input().split()]
lis.sort()
dif = 1000
for i in range(m - n + 1):
	dif = min(dif, rng(lis[i:i + n]))
print(dif)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
best = 1000
for i in range(m - n + 1):
	best = min(best, a[i + n - 1] - a[i])
print(best)


nm = input().split()
n = int(nm[0])
m = int(nm[1])
f = input().split()
for i in range(0, m):
	f[i] = int(f[i])
f.sort()
diff = list()
for j in range(0, m - n + 1):
	diff.append(f[j + n - 1] - f[j])
print(min(diff))


(n, m) = input().split()
n = int(n)
m = int(m)
array = sorted([int(i) for i in input().split()])
res = []
current_dif = 0
pre_elem = None
best_diff = None
start = 0
end = n - 1
while end != m:
	current_diff = array[end] - array[start]
	if best_diff is None:
		best_diff = current_diff
	elif current_diff < best_diff:
		best_diff = current_diff
	start += 1
	end += 1
print(best_diff)


(n, m) = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
l.sort()
r = l[-1] - l[0]
for i in range(m - n + 1):
	r = min(r, l[i + n - 1] - l[i])
print(r)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
i = n - 1
dif = l[i] - l[i - n + 1]
while i < len(l):
	if l[i] - l[i - n + 1] < dif:
		dif = l[i] - l[i - n + 1]
	i += 1
print(dif)


(n, m) = map(int, input().split())
s = list(map(int, input().split()))
s.sort()
minim = 999999
n -= 1
for i in range(n, m):
	if s[i] - s[i - n] < minim:
		minim = s[i] - s[i - n]
print(minim)


def puzzles(n, puz):
	puz.sort()
	min_val = max(puz)
	for i in range(0, len(puz) - n + 1):
		if puz[i + n - 1] - puz[i] < min_val:
			min_val = puz[i + n - 1] - puz[i]
	return min_val
print(puzzles(int(input().split(' ')[0]), [int(a) for a in input().split(' ')]))


(n, m) = map(int, input().split())
lis = sorted(list(map(int, input().split())))
mymin = 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
for i in range(m - n + 1):
	mymin = min(mymin, lis[i + n - 1] - lis[i])
print(mymin)


(n, m) = [int(i) for i in input().split()]
f = sorted((int(i) for i in input().split()))
result = 100000
for i in range(m - n + 1):
	result = min(result, f[i + n - 1] - f[i])
print(result)


(n, m) = map(int, input().split())
inp = sorted(list(map(int, input().split())))
i = 0
j = len(inp)
ans = []
while i <= j - n:
	ans.append(max(inp[i:i + n]) - min(inp[i:i + n]))
	i += 1
print(min(ans))


(n, m) = map(lambda x: int(x), input().split())
p = sorted(map(lambda x: int(x), input().split()))
d = list()
for i in range(m - n + 1):
	d.append(p[i + n - 1] - p[i])
print(min(d))


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


(N, M) = map(int, input().split())
mi = sorted(list(map(int, input().split())))
minimum = float('inf')
for i in range(M - N + 1):
	minimum = min(mi[i + N - 1] - mi[i], minimum)
print(minimum)


def Puzzles(n, m, s):
	s.sort()
	res = []
	for i in range(m - n + 1):
		s1 = []
		for j in range(i, i + n):
			s1.append(s[j])
		res.append(max(s1) - min(s1))
	return min(res)
(n, m) = input().split()
m = int(m)
n = int(n)
s = [int(n) for n in input().split()]
print(Puzzles(n, m, s))


(n, m) = map(int, input().split())
a = [int(i) for i in input().split()]
a = sorted(a)
best = 1000
for k in range(m - n + 1):
	best = min(best, a[k + n - 1] - a[k])
print(best)


import sys
[a, b] = sys.stdin.readline().rstrip().split(' ')
(a, b) = (int(a), int(b))
jigsaws_list = sys.stdin.readline().rstrip().split(' ')
jigsaws_list = [int(x) for x in jigsaws_list]
jigsaws_list.sort()
min_dif = 10000
for i in range(len(jigsaws_list) - a + 1):
	if jigsaws_list[i + a - 1] - jigsaws_list[i] < min_dif:
		min_dif = jigsaws_list[i + a - 1] - jigsaws_list[i]
print(min_dif)


test = input().split()
n = int(test[0])
m = int(test[1])
puzzles = [int(e) for e in input().split()]
puzzles.sort()
min = puzzles[n - 1] - puzzles[0]
x = len(puzzles) - (n - 1)
for i in range(x):
	aux = puzzles[i + n - 1] - puzzles[i]
	if aux < min:
		min = aux
print(str(min))


(n, _) = map(int, input().split())
nums = sorted(map(int, input().split()))
print(min((b - a for (a, b) in zip(nums, nums[n - 1:]))))


(n, m) = [int(x) for x in input().split()]
m = [int(x) for x in input().split()]
m = sorted(m)
best = 10000.0
for i in range(len(m) - n + 1):
	best = min(best, m[i + n - 1] - m[i])
print(best)


a = input()
a = a.split()
a1 = int(a[0])
a2 = int(a[1])
b = input()
b = b.split()
menor = 0
for k in range(len(b)):
	b[k] = int(b[k])
b.sort()
for m in range(len(b) - (a1 - 1)):
	c = b[m + a1 - 1] - b[m]
	if c < menor or (menor == 0 and m == 0):
		menor = c
print(menor)


(m, n) = map(int, input().split())
l = sorted(list(map(int, input().split())))
z = 999999
for i in range(0, n - m + 1):
	if l[i + m - 1] - l[i] < z:
		z = l[i + m - 1] - l[i]
print(z)


import math
(n, m) = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
mn = math.inf
for i in range(0, m - n + 1):
	mn = min(mn, A[i + n - 1] - A[i])
print(mn)


(n, m) = map(int, input().split())
f_list = list(map(int, input().split()))
f_list.sort()
A_B = []
if m == n:
	print(f_list[-1] - f_list[0])
else:
	for x in range(m - n + 1):
		A_B.append(f_list[x + n - 1] - f_list[x])
	print(min(A_B))


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


number = list(map(int, input().split()))
puzzles = list(map(int, input().split()))
puzzles.sort()
difference = []
for i in range(number[1] - number[0] + 1):
	dif = max(puzzles[i:i + number[0]]) - min(puzzles[i:i + number[0]])
	difference.append(dif)
print(min(difference))


nk = input().split()
n = int(nk[0])
k = int(nk[1])
l = list(map(int, input().split()))
l = sorted(l)
r = abs(l[n - 1] - l[0])
for i in range(0, k - n + 1):
	if l[i + n - 1] - l[i] < r:
		r = abs(l[i + n - 1] - l[i])
print(r)


(n, m) = map(int, input().split())
x = sorted([int(i) for i in input().split()])
z = x[-1] - x[0]
if n < m:
	for j in range(m - n + 1):
		a = x[j + n - 1] - x[j]
		if a < z:
			z = a
	print(z)
else:
	print(z)


import math
(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
arr = sorted(arr)
res = float('inf')
for i in range(0, len(arr) - n + 1):
	res = min(res, arr[i + n - 1] - arr[i])
print(res)


(n, m) = map(int, input().split())
arr = sorted(list(map(int, input().split())))
res = max(arr)
for i in range(m - n + 1):
	diff = arr[i + n - 1] - arr[i]
	if diff < res:
		res = diff
print(res)


line = input()
quantity = int(line.split()[0])
line = input()
numbers = [int(i) for i in line.split()]

def quan(d, nums):
	tmp = 0
	for i in nums:
		t = 0
		for j in nums:
			if j <= i:
				if i - j <= d:
					t += 1
		tmp = max(t, tmp)
	return tmp
result = 0
while quan(result, numbers) < quantity:
	result += 1
print(result)


(n, m) = [int(x) for x in input().split()]
puzzles = [int(x) for x in input().split()]
puzzles = sorted(puzzles)
minimum = 10 ** 9 + 7
for k in range(m - n + 1):
	val = puzzles[k + n - 1] - puzzles[k]
	minimum = min(minimum, val)
if m == n:
	print(puzzles[-1] - puzzles[0])
else:
	print(minimum)


(n, m) = list(map(int, input().split()))
nums = list(map(int, input().split()))
nums.sort()
diff = float('inf')
for i in range(m - n + 1):
	if nums[i + n - 1] - nums[i] < diff:
		diff = nums[i + n - 1] - nums[i]
print(diff)


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


(n, m) = map(int, input().split())
p = sorted(list((int(x) for x in input().split())))
pn = [(p[i], p[i + n - 1]) for i in range(len(p) - n + 1)]
t = []
for i in range(len(pn)):
	t.append(pn[i][1] - pn[i][0])
print(min(t))


myn = input()
(Lmyn, num) = ([], '')
for numero in myn:
	if numero != ' ':
		num = num + numero
	else:
		Lmyn.append(int(num))
		num = ''
Lmyn.append(int(num))
fn = input()
(num, L) = ('', [])
for numero in fn:
	if numero != ' ':
		num = num + numero
	else:
		L.append(int(num))
		num = ''
L.append(int(num))
L.sort()
m = Lmyn[0] - 1
Laux = []
for indice in range(Lmyn[1]):
	if m + indice > int(Lmyn[1]) - 1:
		break
	else:
		diferencia = L[indice + m] - L[indice]
		Laux.append(diferencia)
Laux.sort()
print(Laux[0])


li_nm = [int(x) for x in input().split()]
li_m = [int(x) for x in input().split()]
students = li_nm[0]
li_m.sort()
diff = 1000000000
for i in range(0, len(li_m), 1):
	index = i + students - 1
	if index < len(li_m):
		if li_m[index] - li_m[i] < diff:
			diff = li_m[index] - li_m[i]
	else:
		break
print(diff)


(n, m) = map(int, input().split(' '))
arr = list(map(int, input().split(' ')))
min_dif = 10000
arr.sort()
if n == m:
	print(max(arr) - min(arr))
else:
	for x in range(m - n + 1):
		min_dif = min(min_dif, arr[n + x - 1] - arr[x])
	print(min_dif)


(n, m) = map(int, input().split())
num = [int(x) for x in input().split()]
num.sort()
list1 = []
for i in range(m):
	if n + i <= m:
		a = num[n + i - 1] - num[i]
		list1.append(a)
	else:
		pass
list1.sort()
print(list1[0])


n = input()
m = input()
n = [int(x) for x in n.split(' ')]
m = [int(x) for x in m.split(' ')]
m.sort()
q = 10000000000000000
p = 0
k = n[0] - 1
while k < len(m):
	if q > m[k] - m[p]:
		q = m[k] - m[p]
	p += 1
	k += 1
print(q)


s = input().split(' ')
n = int(s[0]) - 1
m = int(s[1])
s = list(map(int, input().split(' ')))
s.sort()
smallestDif = 1000000
for i in range(n, len(s)):
	if s[i] - s[i - n] < smallestDif:
		smallestDif = s[i] - s[i - n]
print(smallestDif)


def puzzles(n, m, lst):
	lst.sort()
	ans = lst[n - 1] - lst[0]
	for i in range(1, m - n + 1):
		if lst[i + n - 1] - lst[i] < ans:
			ans = lst[i + n - 1] - lst[i]
	return ans
(n, m) = map(int, input('').split(' '))
lst = list(map(int, input('').split(' ')))
print(puzzles(n, m, lst))


(m, n) = map(int, input().split())
l = list(map(int, input().split()))
k = sorted(l)
best = 100000000
for i in range(n - m + 1):
	best = min(best, abs(k[i] - k[i + m - 1]))
print(best)


nm1 = input()
nm2 = nm1.split()
n = int(nm2[0])
m = int(nm2[1])
nums = input()
num = nums.split()
num = list(map(int, num))
num.sort()
history = 99999
for z in range(m - n + 1):
	reader = []
	for x in range(n):
		reader.append(num[x + z])
		x += 1
	sub = reader[n - 1] - reader[0]
	if sub > history:
		pass
	elif sub < history:
		history = sub
print(history)


palabra = input().split()
number_alumnos = int(palabra[0])
number_puzzles = int(palabra[1])
lista = []
for i in input().split():
	lista.append(int(i))
lista = sorted(lista)
minim = max(lista) - min(lista)
for i in range(number_puzzles - number_alumnos + 1):
	if lista[i + number_alumnos - 1] - lista[i] < minim:
		minim = lista[i + number_alumnos - 1] - lista[i]
print(minim)


(n, m) = map(int, input().split())
lst = sorted(map(int, input().split()))
ans = 1001
for i in range(m - n + 1):
	k = lst[i:i + n]
	if k[-1] - k[0] < ans:
		ans = k[-1] - k[0]
print(ans)


(n, m) = map(int, input().split())
f = [int(x) for x in input().split()]
f.sort()
l = []
c = 0
i = 0
while c < m:
	c = i + n - 1
	if c >= m:
		break
	l.append(f[c] - f[i])
	i += 1
print(min(l))


(n, m) = map(int, input().split())
puzzles = list(map(int, input().split()))
puzzles.sort()
i = 0
while i < m - n:
	a = puzzles[:n]
	b = puzzles[-n:]
	if a[-1] - a[0] > b[-1] - b[0]:
		del puzzles[0]
	else:
		del puzzles[-1]
	i += 1
print(puzzles[-1] - puzzles[0])


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
res = 100000000000.0
f.sort()
i = n - 1
j = 0
temp = 0
while i < len(f):
	temp = abs(f[j] - f[i])
	if temp < res:
		res = temp
	j += 1
	i += 1
print(res)


import math

def puzzle(s, l):
	s.sort()
	p = []
	for i in list(range(1 + len(s) - l)):
		p.append(s[i + l - 1] - s[i])
	return min(p)
(l, r) = map(int, input().split())
s = list(map(int, input().split()))
print(puzzle(s, l))


(m, n) = map(int, input().split())
l = sorted(list(map(int, input().split())))
b = 1000000
for i in range(n - m + 1):
	b = min(b, l[i + m - 1] - l[i])
print(b)


o = input().rstrip().split(' ')
p = input().rstrip().split(' ')
p.sort(key=int)
mini = 1000000000000000
for i in range(0, len(p) - int(o[0]) + 1):
	A = p[i:i + int(o[0])]
	if int(A[len(A) - 1]) - int(A[0]) < mini:
		mini = int(A[len(A) - 1]) - int(A[0])
print(mini)


import sys
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
mini = sys.maxsize
i = 0
b = []
miny = 0
j = 0
a.sort()
for i in range(m + n - 1):
	j = i
	while j + n - 1 < len(a):
		b = a[j:j + n]
		miny = abs(max(b) - min(b))
		mini = min(mini, miny)
		j = j + n
		b = []
print(mini)


(x, n) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
m = 10 ** 10
for i in range(n - x + 1):
	s = l[i + (x - 1)] - l[i]
	if s < m:
		m = s
print(m)


(n, m) = map(int, input().split())
A = sorted(map(int, input().split()))
(i, j) = (0, n - 1)
cnt = 10000000000
while j < m:
	cnt = min(cnt, A[j] - A[i])
	(i, j) = (i + 1, i + n)
print(cnt)


_n = input().split(' ')
n = int(_n[0])
m = int(_n[1])
_list = input().split(' ')
out_list = []
dif_list = []
for elem in _list:
	out_list.append(int(elem))
out_list.sort()
for i in range(n - 1, len(out_list)):
	dif_list.append(out_list[i] - out_list[i - (n - 1)])
dif_list.sort()
print(min(dif_list))


(n, m) = map(int, input().split())
list_p = list(map(int, input().split()))
list_p.sort()
minum = 10000
for i in range(m - n + 1):
	minum = min(minum, list_p[i + (n - 1)] - list_p[i])
print(minum)


from sys import stdin
minn = 0
s = []
res = []
(n, m) = map(int, input().split())
a = sorted([int(x) for x in stdin.readline().split()])
d = m - n
for i in range(m):
	if i + n <= m:
		s = a[i:i + n]
		val = max(s) - min(s)
		res.append(val)
		s = 0
		val = 0
	elif i + n > m:
		minn = min(res)
		print(minn)
		exit()


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


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


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


import sys
(n, m) = map(int, sys.stdin.readline().rstrip().split())
listOfPuzzles = map(int, sys.stdin.readline().rstrip().split())
listOfPuzzles = sorted(listOfPuzzles)
minDiff = sys.maxsize
for i in range(len(listOfPuzzles) - n + 1):
	if listOfPuzzles[i + n - 1] - listOfPuzzles[i] < minDiff:
		minDiff = listOfPuzzles[i + n - 1] - listOfPuzzles[i]
print(minDiff)


(n, m) = map(int, input().split())
a = sorted(list(map(int, input().split())))
mn = a[-1]
for i in range(m - n + 1):
	if a[i + n - 1] - a[i] < mn:
		mn = a[i + n - 1] - a[i]
print(mn)


(m, n) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
x = []
x1 = 1000000000.0
for i in range(n - m + 1):
	x = l[i:i + m]
	x1 = min(x1, max(x) - min(x))
print(x1)


(n, m) = map(int, input().split())
li = list(map(int, input().split()))
li.sort()
diff = 99999999999999
for i in range(n - 1, len(li)):
	d = li[i] - li[i - (n - 1)]
	if d < diff:
		diff = d
print(diff)


(kupit, predmetov) = map(int, input().split())
predmety = list(map(int, input().split()))
predmety.sort(reverse=True)
mini = predmety[0] - predmety[kupit - 1]
for i in range(1, predmetov - kupit + 1):
	mini = min(mini, predmety[i] - predmety[i + kupit - 1])
print(mini)


(x, y) = map(int, input().split())
num = list(map(int, input().strip().split()))[:y]
nu = sorted(num)
c = []
for i in range(x, y + 1):
	c.append(abs(nu[i - 1] - nu[i - x]))
print(min(c))


(x, y) = [int(w) for w in input().split()]
li = [int(xx) for xx in input().split()]
li.sort()
mi = float('inf')
for i in range(y - x + 1):
	now = li[i + x - 1] - li[i]
	if now < mi:
		mi = now
print(mi)


(n, m) = input().split()
[n, m] = [int(n), int(m)]
b = [int(b) for b in input().split()]
b.sort()
d = []
x = 0
y = n - 1
diff = 0
while y < m:
	diff = b[y] - b[x]
	d.append(diff)
	y = y + 1
	x = x + 1
d.sort()
print(d[0])


(n, m) = map(int, input().split())
l = sorted(list(map(int, input().split())))
low = l[m - 1]
for i in range(len(l) - n + 1):
	low = min(low, l[i + n - 1] - l[i])
print(low)


(num, puz) = map(int, input().split())
pieces = [int(x) for x in input().split()]
pieces.sort()
mini = pieces[puz - 1] - pieces[0]
for i in range(0, puz - num + 1):
	if mini > pieces[num + i - 1] - pieces[i]:
		mini = pieces[num + i - 1] - pieces[i]
print(mini)


(n, m) = map(int, input().split())
l = [int(x) for x in input().split()]
l.sort()
ans = 1001
for i in range(m - n + 1):
	c = l[i + n - 1] - l[i]
	ans = min(c, ans)
print(ans)


(s, p) = map(int, input().split())
(*arr,) = sorted(map(int, input().split()))
minval = 9999
for i in range(p - s + 1):
	temp_max = 0
	temp_min = 9999
	for j in range(i, i + s):
		if arr[j] > temp_max:
			temp_max = arr[j]
		if arr[j] < temp_min:
			temp_min = arr[j]
	if temp_max - temp_min < minval:
		minval = temp_max - temp_min
print(minval)


def mod():
	n = list(map(int, input().split()))
	x = list(map(int, input().split()))
	x.sort(reverse=True)
	g = []
	i = 0
	j = n[0] - 1
	while i < len(x):
		if i + j != len(x):
			c = x[i] - x[i + j]
			g.append(c)
			i = i + 1
		else:
			print(min(g))
			break
mod()


inp = input().split()
n = int(inp[0])
m = int(inp[1])
inp = input().split()
a = []
for i in range(m):
	a.append(int(inp[i]))
a.sort()
ans = int(1001)
i = n - 1
while i < m:
	ans = min(ans, a[i] - a[i - n + 1])
	i = i + 1
print(ans)


(n, m) = input().split(' ')
n = int(n)
m = int(m)
s = input()
l = list(map(int, s.split()))
a = sorted(l)
if m <= n:
	ans = max(l) - min(l)
else:
	least = a[n - 1] - a[0]
	j = m - n
	for i in range(1, j + 1):
		if a[i + (n - 1)] - a[i] < least:
			least = a[i + (n - 1)] - a[i]
	ans = least
print(ans)


n = int(input().split(' ')[0])
arr = [int(i) for i in input().split(' ')]
arr.sort()
diff = []
for i in range(len(arr) - n + 1):
	diff.append(arr[i + n - 1] - arr[i])
print(min(diff))


import sys
(n, m) = [int(i) for i in input().split()]
f = [int(i) for i in input().split()]
f = sorted(f)
smin = sys.maxsize
for i in range(m - n + 1):
	smin = min(f[i + n - 1] - f[i], smin)
print(smin)


import math

def solve():
	(n, m) = map(int, input().strip().split())
	arr = list(map(int, input().strip().split()))
	arr.sort(reverse=True)
	ans = 10000
	for i in range(m - n + 1):
		if arr[i] - arr[i + n - 1] < ans:
			ans = arr[i] - arr[i + n - 1]
	return ans
print(solve())


(n, m) = [int(x) for x in input().strip().split()]
vals = [int(x) for x in input().strip().split()]
vals = sorted(vals)
mins = 10 ** 5
for i in range(0, m - n + 1):
	mins = min(mins, vals[i + n - 1] - vals[i])
print(mins)


(n, m) = map(int, input().split(' '))
f = input().split(' ')
lst = [int(i) for i in f]
sorted_lst = sorted(lst)
mins = sorted_lst[n - 1] - sorted_lst[0]
for i in range(1, m - n + 1):
	data = sorted_lst[i + n - 1] - sorted_lst[i]
	if data < mins:
		mins = data
print(mins)


(n, m) = map(int, input().split())
d = sorted(list(map(int, input().split())))
res = min([d[i] - d[i - n + 1] for i in range(n - 1, m)])
print(res)


(n, m) = map(int, input().split())
l = input().split()
number = [int(x) for x in l]
numbers = sorted(number)
print(min((j - i for (i, j) in zip(numbers, numbers[n - 1:]))))


n = list(map(int, input().split()))
puzz = list(map(int, input().split()))
puzz.sort()
i = 0
shortest = puzz[n[0] - 1 + i] - puzz[i]
while n[0] - 1 + i < len(puzz):
	if puzz[n[0] - 1 + i] - puzz[i] < shortest:
		shortest = puzz[n[0] - 1 + i] - puzz[i]
	i += 1
print(shortest)


(n, m) = map(int, input().split())
vals = sorted(map(int, input().split()[:m]))
res = 2000
for i in range(m - n + 1):
	d = vals[i + n - 1] - vals[i]
	if d < res:
		res = d
print(res)


(x, y) = input().split(' ')
z = input().split(' ')
z = list(map(int, z))
for i in range(1, len(z)):
	j = i - 1
	element = z[i]
	while z[j] > element and j >= 0:
		z[j + 1] = z[j]
		j = j - 1
	z[j + 1] = element
s = z[int(x) - 1] - z[0]
for i in range(1, int(y) - int(x) + 1):
	if s > z[i + int(x) - 1] - z[i]:
		s = z[i + int(x) - 1] - z[i]
	else:
		s = s
print(s)


(n, m) = map(int, input().split())
puzzles = list(map(int, input().split()))
puzzles = sorted(puzzles)
Min = 1000000
for i in range(m - n + 1):
	if puzzles[i + n - 1] - puzzles[i] < Min:
		Min = puzzles[i + n - 1] - puzzles[i]
print(Min)


(n, m) = map(int, input().split())
l = [int(i) for i in input().split()]
l.sort()
d = l[n - 1] - l[0]
for i in range(1, m - n + 1):
	if d > l[i + n - 1] - l[i]:
		d = l[i + n - 1] - l[i]
print(d)


(n, m) = map(int, input().split())
Line = [int(i) for i in input().split()]
Line.sort()
k = len(Line)
p = 9999
for i in range(k - n + 1):
	p = min(p, Line[i + n - 1] - Line[i])
print(p)


l = list(map(int, input().split()))
(n, m) = (l[0], l[1])
l = list(map(int, input().split()))
l = sorted(l)
i = 0
d = []
while i <= m - n:
	x = l[i:i + n]
	d = d + [max(x) - min(x)]
	i += 1
print(min(d))


(n, m) = map(int, input().split())
puzzles = sorted([int(x) for x in input().split()])
result = []
for i in range(m - n + 1):
	temp = puzzles[i:i + n]
	result.append(max(temp) - min(temp))
print(min(result))


a = input()
a = a.split(' ')
x = int(a[1])
a = int(a[0])
b = input()
b = b.split(' ')
b = [*map(int, b)]
b = sorted(b)
c = list(set(b))
m = 999999999
for i in range(x - a + 1):
	if m > b[a + i - 1] - b[i]:
		m = b[a + i - 1] - b[i]
print(m)


(n, m) = map(int, input().split())
arr = sorted([int(x) for x in input().split()])
_min = 1001
for i in range(m - n + 1):
	c = arr[i + n - 1] - arr[i]
	if c < _min:
		_min = c
print(_min)


(n, m) = [int(x) for x in input().strip().split(' ')]
nums = [int(x) for x in input().strip().split(' ')]
nums = sorted(nums)
minDiff = nums[n - 1] - nums[0]
for index in range(n - 1, len(nums)):
	minDiff = min(minDiff, nums[index] - nums[index - n + 1])
print(minDiff)


y = list(map(int, input().split()))
(n, k) = (y[0], y[1])
x = list(map(int, input().split()))
x.sort()
mini = int(10000)
for i in range(k - n + 1):
	mini = min(mini, int(x[i + n - 1] - x[i]))
print(mini)


(n, m) = input().split()
mass = input().split(' ')
n = int(n)
m = int(m)
mn = 1001
for i in range(m):
	mass[i] = int(mass[i])
mass.sort()
k = n - 1
for i in range(m):
	if mass[k] - mass[i] < mn:
		mn = mass[k] - mass[i]
	if k == m - 1:
		break
	k += 1
print(mn)


_n = input().split(' ')
n = int(_n[0])
m = int(_n[1])
_list = input().split(' ')
out_list = []
for elem in _list:
	out_list.append(int(elem))
out_list.sort()
dif = max(out_list) - min(out_list)
for i in range(n - 1, len(out_list)):
	if out_list[i] - out_list[i - (n - 1)] < dif:
		dif = out_list[i] - out_list[i - (n - 1)]
print(dif)


nm = input()
nm = nm.split(' ')
n = int(nm[0])
m = int(nm[1])
f = input()
f = f.split(' ')
for i in range(m):
	f[i] = int(f[i])
if n == m:
	print(max(f) - min(f))
else:
	f.sort()
	gap = set()
	for i in range(m - n + 1):
		gap.add(f[i + n - 1] - f[i])
	print(min(gap))


(n, m) = map(int, input().split())
v = [int(i) for i in input().split()]
v.sort()
mi = v[-1] - v[0]
for i in range(m - n + 1):
	if v[i + n - 1] - v[i] < mi:
		mi = v[i + n - 1] - v[i]
print(mi)


import logging
fmt = '%(levelname)s - %(name)s (line:%(lineno)s) - %(message)s'
formatter = logging.Formatter(fmt)
ch = logging.StreamHandler()
ch.setLevel(logging.ERROR)
ch.setFormatter(formatter)
logger = logging.getLogger('puzzles')
logger.setLevel(logging.ERROR)
logger.addHandler(ch)

def solve(n, seq):
	seq = sorted(seq)
	return min([abs(seq[i] - seq[i + n - 1]) for i in range(len(seq) - n + 1)])

def main():
	(n, _) = map(int, input().strip().split())
	seq = [int(x) for x in input().strip().split()]
	result = solve(n, seq)
	print(result)
main()


import math
(n, k) = input().split(' ')
n = int(n)
k = int(k)
l = [int(x) for x in input().split()]
l.sort()
m = l[n - 1] - l[0]
for i in range(k - n + 1):
	m = min(l[i + n - 1] - l[i], m)
print(m)


(n, m) = map(int, input().split())
arr = sorted(list(map(int, input().split())))
differences = []
for i in range(0, len(arr)):
	try:
		differences.append(arr[i + n - 1] - arr[i])
	except:
		pass
print(min(differences))


import sys
input = sys.stdin.readline

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


l = lambda : map(int, input().split())
(n, m) = l()
arr = sorted(map(int, input().split()))
if n == m:
	sum = arr[n - 1] - arr[0]
else:
	sum = 10000
for i in range(0, m - n + 1):
	if arr[i + n - 1] - arr[i] <= sum:
		sum = arr[i + n - 1] - arr[i]
print(sum)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
diff = l[m - 1] - l[0]
for j in range(0, m - n + 1):
	x = l[j + n - 1] - l[j]
	if x < diff:
		diff = x
print(diff)


line = list(map(int, input().split()))
(n, m) = (line[0], line[1])
fridge = list(map(int, input().split()))
fridge.sort()
fridge_answer = list()
counter = -1
while counter != len(fridge) - n:
	fridge_counter = list()
	counter += 1
	for i in range(counter, counter + n):
		fridge_counter.append(fridge[i])
	fridge_answer.append(max(fridge_counter) - min(fridge_counter))
print(min(fridge_answer))


d = [int(i) for i in input().split(' ')]
n = d[0]
s = [int(i) for i in input().split(' ')]
s.sort(reverse=True)
mindif = 10000
for i in range(len(s)):
	if i + n <= len(s) and s[i] - s[i + n - 1] < mindif:
		mindif = s[i] - s[i + n - 1]
print(mindif)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
c = float('infinity')
for i in range(m - n + 1):
	c = min(c, abs(a[i] - a[i + n - 1]))
print(c)


(n, m) = [int(x) for x in input().split(' ')]
lst = [int(x) for x in input().split(' ')]
lst.sort()
lowest = 2000
for i in range(n - 1, m):
	if lst[i] - lst[i - (n - 1)] < lowest:
		lowest = lst[i] - lst[i - (n - 1)]
print(lowest)


(n, m) = map(int, input().split())
p = [int(x) for x in input().split()]
p.sort()
a = p[n - 1] - p[0]
for i in range(m - n + 1):
	q = p[i + n - 1] - p[i]
	if q <= a:
		a = q
print(a)


(n, m) = map(int, input().split())
s = tuple(map(int, input().split()))
s = sorted(s)
min1 = sum(s)
i = 0
while i <= m - n:
	if s[i + n - 1] - s[i] < min1:
		min1 = s[i + n - 1] - s[i]
	i = i + 1
print(min1)


(n, m) = [int(x) for x in input().split()]
se = sorted([int(x) for x in input().split()])
a = se[-1] - se[0]
for i in range(m - n + 1):
	b = se[i + n - 1] - se[i]
	a = min(a, b)
print(a)


from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def powmod(a, b):
	a %= mod
	if a == 0:
		return 0
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % mod
		a = a * a % mod
		b >>= 1
	return res

def main():
	(n, m) = mi()
	a = li()
	a.sort()
	ans = a[n - 1] - a[0]
	for i in range(n, m):
		ans = min(ans, a[i] - a[i - n + 1])
	print(ans)
main()


(n, m) = map(int, input().split())
puzzles = list(map(int, input().split()))
min_diff = 10000000000000000
puzzles.sort()
for i in range(0, m - n + 1):
	diff = puzzles[i + n - 1] - puzzles[i]
	if diff < min_diff:
		min_diff = diff
print(min_diff)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
d = []
i = 0
j = n - 1
while j < m:
	b = a[j] - a[i]
	d.append(b)
	i += 1
	j += 1
print(min(d))


(k, n) = list(map(int, input().split()))
num_pieces = list(map(int, input().split()))
num_pieces.sort()
while n > k:
	if num_pieces[k - 1] - num_pieces[0] >= num_pieces[-1] - num_pieces[-k]:
		num_pieces = num_pieces[1:]
	else:
		num_pieces = num_pieces[:-1]
	n = len(num_pieces)
print(num_pieces[-1] - num_pieces[0])


a = input()
a1 = a.split(' ')
n = int(a1[0])
m = int(a1[1])
string = input()
s = string.split(' ')
num = [0] * m
for i in range(m):
	num[i] = int(s[i])
num.sort()
bot = 0
up = n - 1
mn = num[m - 1] - num[0]
while up <= m - 1:
	k = num[up] - num[bot]
	if k < mn:
		mn = k
	up += 1
	bot += 1
print(mn)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
p = m - n
diff = max(l)
for i in range(m - n + 1):
	high = max(l[i:i + n])
	low = min(l[i:i + n])
	if diff > high - low:
		diff = high - low
print(diff)


(n, m) = [int(x) for x in input().split()]
f = [int(x) for x in input().split()]
f.sort()
p = []
for i in range(m - n + 1):
	L = f[i:n + i]
	diff = max(L) - min(L)
	p.append(diff)
print(min(p))


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


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


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
ans = max(l) - min(l)
i = 0
j = n - 1
fans = 10000000000
while True:
	if abs(l[i] - l[j]) < ans:
		ans = abs(l[i] - l[j])
		fans = min(ans, fans)
		i += 1
		j += 1
	else:
		i += 1
		j += 1
	if j >= len(l) or i >= len(l):
		break
check = max(l) - min(l)
print(min(check, fans))


(n, m) = (int(x) for x in input().split())
raw_number = input().split()
numbers = list(raw_number)
number = list(map(int, numbers))
number.sort()
jicha = []
for i in range(0, m - n + 1):
	jc = number[i + n - 1] - number[i]
	jicha.append(jc)
if len(jicha) != 0:
	print(min(jicha))
else:
	print(0)


import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue

class Scanner:

	@staticmethod
	def int():
		return int(sys.stdin.readline().rstrip())

	@staticmethod
	def string():
		return sys.stdin.readline().rstrip()

	@staticmethod
	def map_int():
		return [int(x) for x in Scanner.string().split()]

	@staticmethod
	def string_list(n):
		return [input() for i in range(n)]

	@staticmethod
	def int_list_list(n):
		return [Scanner.map_int() for i in range(n)]

	@staticmethod
	def int_cols_list(n):
		return [int(input()) for i in range(n)]

class Math:

	@staticmethod
	def gcd(a, b):
		if b == 0:
			return a
		return Math.gcd(b, a % b)

	@staticmethod
	def lcm(a, b):
		return a * b // Math.gcd(a, b)

	@staticmethod
	def round_up(a, b):
		return -(-a // b)

	@staticmethod
	def is_prime(n):
		if n < 2:
			return False
		if n == 2:
			return True
		if n % 2 == 0:
			return False
		d = int(n ** 0.5) + 1
		for i in range(3, d + 1, 2):
			if n % i == 0:
				return False
		return True

class PriorityQueue:

	def __init__(self, l=[]):
		self.q = l
		heapq.heapify(self.q)
		return

	def push(self, n):
		heapq.heappush(self.q, n)
		return

	def pop(self):
		return heapq.heappop(self.q)
MOD = int(1000000000.0) + 7
INF = int(1000000000000000.0)

def main():
	(N, M) = Scanner.map_int()
	A = Scanner.map_int()
	A.sort()
	ans = INF
	for i in range(M - N + 1):
		ans = min(A[i + N - 1] - A[i], ans)
	print(ans)
main()


import math
(n, m) = [int(i) for i in input().split()]
f = sorted([int(i) for i in input().split()])
best = 1001
for k in range(m - n + 1):
	best = min(best, f[k + n - 1] - f[k])
if best != 1001:
	print(best)
else:
	print(0)


(n, m) = (int(i) for i in input().split())
a = sorted([int(i) for i in input().split()])
x = 10000
for k in range(m - n + 1):
	x = min(x, a[k + n - 1] - a[k])
print(x)


(n, m) = [int(i) for i in input().split(' ')]
puzzles = [int(i) for i in input().split(' ')]
puzzles.sort()
current_min = float('inf')
for i in range(0, m - n + 1):
	current_min = min(current_min, puzzles[i + n - 1] - puzzles[i])
print(current_min)


l = list(map(int, input().split()))
(n, m) = (l[0], l[1])
a = list(map(int, input().split()))
ans = max(a) - min(a)
a.sort()
for i in range(0, m - n + 1):
	b = a[i:i + n]
	p = max(b)
	q = min(b)
	if ans > p - q:
		ans = p - q
print(ans)


(a, b) = map(int, input().split())
xs = sorted([int(x) for x in input().split()])
s = xs[-1] - xs[0]
for i in range(b - a + 1):
	s = min(s, xs[i + a - 1] - xs[i])
print(s)


def main():
	input1 = input().strip().split()
	num_students = int(input1[0])
	num_puzzles = int(input1[1])
	input2 = input().strip().split()
	puzzle_values = sorted([int(i) for i in input2])
	if contains_num_of_repeat(num_students, puzzle_values):
		print(0)
	else:
		first_slice = puzzle_values[0:num_students]
		lowest_dif = max(first_slice) - min(first_slice)
		for i in range(1, num_puzzles - num_students + 1):
			slice = puzzle_values[i:num_students + i]
			dif = abs(max(slice) - min(slice))
			if dif < lowest_dif:
				lowest_dif = dif
		print(lowest_dif)

def contains_num_of_repeat(num_repeats, puzzle_values):
	for val in puzzle_values:
		if puzzle_values.count(val) >= num_repeats:
			return True
	return False
main()


(k, n) = map(int, input().split())
pieces = list(map(int, input().split()))
pieces.sort()
result = +543295835
for i in range(n - k + 1):
	result = min(result, pieces[i + k - 1] - pieces[i])
print(result)


a = list(map(int, input().strip().split(' ')))
b = list(map(int, input().strip().split(' ')))
b.sort()
mi = 12345678
for i in range(a[1] - a[0] + 1):
	c = b[i:i + a[0]]
	if c[-1] - c[0] < mi:
		mi = c[-1] - c[0]
print(mi)


(n, m) = map(int, input().split())
p = sorted(list(map(int, input().split())))
maxSoFar = 10 ** 6
for i in range(m - n + 1):
	first = i
	last = n - 1 + i
	maxSoFar = min(maxSoFar, abs(p[first] - p[last]))
print(maxSoFar)


(n, m) = map(int, input().split())
list = list(map(int, input().split()))
list.sort()
i = 0
l = []
while i <= m - n:
	s = list[i:i + n]
	a = s[-1] - s[0]
	l.append(a)
	i = i + 1
l.sort()
print(l[0])


nm = list(map(int, input().rstrip().split()))
n = nm[0]
m = nm[1]
line = list(map(int, input().rstrip().split()))
line.sort(reverse=True)
minimum = 4000
for i in range(m - n + 1):
	maximum = max(line[i:i + n])
	mini = min(line[i:i + n])
	diff = maximum - mini
	minimum = min(minimum, diff)
print(minimum)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
best = 10 ** 5
for k in range(m - n + 1):
	best = min(best, a[k + n - 1] - a[k])
print(best)


a = input().split(' ')
b = input().split(' ')
b = list(map(int, b))
b = sorted(b)
min = int(b[int(a[0]) - 1] - int(b[0]))
for i in range(int(a[1]) - int(a[0]) + 1):
	if min > int(b[int(a[0]) + i - 1] - b[i]):
		min = int(b[int(a[0]) + i - 1] - b[i])
print(min)


quota = [int(s) for s in input().split()]
puzzles = [int(p) for p in input().split()]
puzzles.sort(reverse=True)
minimum = puzzles[0] * quota[0]
place = 0
if quota[0] == quota[1]:
	print(max(puzzles) - min(puzzles))
else:
	for pos in range(quota[1] - quota[0] + 1):
		division = puzzles[0 + pos:quota[0] + pos]
		if max(division) - min(division) < minimum:
			minimum = max(division) - min(division)
			place = pos
	section = puzzles[0 + place:quota[0] + place]
	print(max(section) - min(section))


(n, m) = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
l.sort()
x = []
for i in range(0, m - n + 1):
	x.append(abs(l[i] - l[i + n - 1]))
print(min(x))


def main():
	(n, m) = (int(x) for x in input().split())
	lst = [int(x) for x in input().split()]
	lst.sort()
	c_min = lst[m - 1]
	for it in range(0, m - n + 1):
		c_min = min(c_min, lst[it + n - 1] - lst[it])
	print(c_min)
main()


nm = input().split()
(n, m) = (int(nm[0]), int(nm[1]))
arr = sorted(list(map(int, input().split())))
least = 10 ** 4
for i in range(n, m + 1):
	check = arr[i - 1] - arr[i - n]
	least = least if least < check else check
print(least)


(n, m) = [int(x) for x in input().split()]
f = sorted([int(x) for x in input().split()])
minDiff = float('inf')
for idx in range(m - n + 1):
	minDiff = min(f[idx + n - 1] - f[idx], minDiff)
print(minDiff)


(n, m) = [int(i) for i in input().split()]
numbers = [int(i) for i in input().split()]
numbers.sort()
AB = []
for i2 in range(n - 1, m):
	i1 = i2 - n + 1
	diff = numbers[i2] - numbers[i1]
	AB.append(diff)
print(min(AB))


def least_difference(students, puzzles):
	if len(puzzles) == students:
		return max(puzzles) - min(puzzles)
	if len(puzzles) < students:
		return 0
	split = puzzles[:students]
	diff = puzzles[students - 1] - puzzles[0]
	newdiff = least_difference(students, puzzles[1:])
	if newdiff < diff:
		return newdiff
	else:
		return diff
students = list(map(int, input().split(' ')))[0]
puzzles = list(map(int, input().split(' ')))
puzzles = sorted(puzzles)
difference = least_difference(students, puzzles)
print(difference)


str1 = input()
str2 = input()
list1 = str1.split(' ')
n = int(list1[0])
m = int(list1[1])
dlist = []
list2 = str2.split(' ')
list2 = list(map(int, list2))
list2.sort()
for i in range(0, m - n + 1):
	dlist.append(int(list2[i + n - 1]) - int(list2[i]))
print(min(dlist))


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


(n, m) = map(int, input().split())
arr = [int(i) for i in input().split()]
arr.sort()
mini = 1000000000.0
for i in range(m - n + 1):
	mini = min(mini, arr[i + n - 1] - arr[i])
print(mini)


(n, m) = map(int, input().split())
list1 = sorted([int(x) for x in input().split()])
list2 = []
a = m - n
for i in range(1, a + 2):
	x = list1[n - 1] - list1[i - 1]
	list2.append(x)
	n += 1
print(min(list2))


(a, m) = map(int, input().split())
b = [int(x) for x in input().split()]
c = []
b.sort()
if a == m:
	print(max(b) - min(b))
else:
	for i in range(m - a + 1):
		c.append(b[a - 1 + i] - b[i])
	print(min(c))


import sys
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
x = sys.maxsize
for i in range(0, m - n + 1):
	x = min(x, a[i + n - 1] - a[i])
print(x)


(n, m) = map(int, input().split())
arr = sorted(list(map(int, input().split())))
less = 1000
for x in range(m - n + 1):
	sub = arr[x:x + n]
	diff = sub[-1] - sub[0]
	if diff < less:
		less = diff
print(less)


(n, m) = map(int, input().split())
jigsaw = input().split()
i = 0
while i < m:
	jigsaw[i] = int(jigsaw[i])
	i = i + 1
jigsaw.sort(reverse=True)
difference = []
j = 0
while j < m - n + 1:
	difference.append(jigsaw[j] - jigsaw[j + n - 1])
	j = j + 1
difference.sort()
print(difference[0])


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


import math
tc = list(map(int, input().split()))
n = tc[0]
m = tc[1]
best = math.inf
l = list(map(int, input().split()))
l.sort()
for i in range(0, m - n + 1):
	best = min(best, l[n + i - 1] - l[i])
print(best)


from sys import stdin, stdout
I = lambda : stdin.readline().strip()
read = lambda : list(map(int, input().split()))
(n, m) = read()
arr = read()
arr.sort()
diff_min = 10 ** 9
for i in range(m - n + 1):
	diff_min = min(diff_min, arr[i + n - 1] - arr[i])
print(diff_min)


(n, m) = map(int, input().split())
gifts = sorted(list(map(int, input().split())))
output = abs(gifts[0] - gifts[n - 1])
for i in range(len(gifts) - n + 1):
	output = min(output, abs(gifts[i] - gifts[i + n - 1]))
print(output)


N_M = input().split()
(N, M) = (int(N_M[0]), int(N_M[1]))
puzzles = input().split()
puzzles = list(map(int, puzzles))
difference_counter = []
puzzles = sorted(puzzles)
for P_idx in range(M):
	stu_counter = 0
	students_tmp = []
	S_idx = P_idx
	while True:
		if stu_counter == N:
			break
		if S_idx == M - 1:
			students_tmp.append(puzzles[S_idx])
			S_idx = 0
			stu_counter += 1
			continue
		students_tmp.append(puzzles[S_idx])
		S_idx += 1
		stu_counter += 1
	difference_counter.append(max(students_tmp) - min(students_tmp))
print(min(difference_counter))


(n, m) = [int(x) for x in input().split()]
puz = [int(x) for x in input().split()]
puz.sort()
mindif = puz[-1] - puz[0]
for i in range(m - n + 1):
	if puz[i + n - 1] - puz[i] < mindif:
		mindif = puz[i + n - 1] - puz[i]
print(mindif)


(n, m) = [int(i) for i in input().split()]
f = list(map(int, input().split()))
f.sort()
q = f[n - 1] - f[0]
for i in range(n, m):
	q = min(q, f[i] - f[i - n + 1])
print(q)


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
f.sort()
best = float('inf')
for i in range(0, m - n + 1):
	best = min(best, f[i + n - 1] - f[i])
if best == float('inf'):
	print(0)
else:
	print(best)


import sys
(n, m) = map(int, input().split())
ar = list(map(int, input().split()))
ar.sort()
minimum = sys.maxsize
for i in range(m - n + 1):
	tmp = ar[i + n - 1] - ar[i]
	minimum = min(tmp, minimum)
print(minimum)


(n, m) = [int(i) for i in input().split()]
puzzleList = [int(i) for i in input().split()]
puzzleList.sort()
minSub = max(puzzleList)
for i in range(0, m - n + 1):
	aux = max(puzzleList[i:n + i]) - min(puzzleList[i:n + i])
	minSub = min(aux, minSub)
print(minSub)


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


(n, m) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
min1 = 999999999999
for i in range(m - n + 1):
	min1 = min(a[i + n - 1] - a[i], min1)
print(min1)


def main():
	(n, m) = map(int, input().split())
	lst = [int(x) for x in input().split()]
	lst.sort()
	mi = float('INF')
	for i in range(m - n + 1):
		loc_mi = lst[i + n - 1] - lst[i]
		mi = min(mi, loc_mi)
	print(mi)
main()


(c, n) = map(int, input().split())
l = list(map(int, input().split()))
t = 99999
l.sort()
for i in range(0, n - c + 1):
	a = min(l[i:i + c])
	b = max(l[i:i + c])
	temp = b - a
	if temp < t:
		t = temp
print(t)


from sys import stdin, exit
(n, m) = map(int, stdin.readline().split(' '))
nums = list(map(int, stdin.readline().split(' ')))
nums.sort()
l = 0
r = n - 1
min_diff = nums[r] - nums[l]
while r < len(nums):
	min_diff = min(min_diff, nums[r] - nums[l])
	l += 1
	r += 1
print(min_diff)


def puz(n, l):
	l.sort()
	m = abs(l[0] - l[n - 1])
	for i in range(1, len(l) - n + 1):
		c = abs(l[i] - l[i + n - 1])
		if c < m:
			m = c
	print(m)
	return
t = input()
l = list(map(int, t.split(' ')))
n = input()
l1 = list(map(int, n.split(' ')))
puz(l[0], l1)


(n, p) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
(c, m) = (0, 10000000000000)
for i in range(p):
	for j in range(i + n - 1, p):
		c = a[j] - a[i]
		if c < m:
			m = c
print(m)


(n, m) = [int(i) for i in input().split()]
g = sorted([int(i) for i in input().split()])
leastsofar = float('inf')
for x in range(n - 1, m):
	c = g[x] - g[x - n + 1]
	if c < leastsofar:
		leastsofar = c
print(leastsofar)


(a, b) = map(int, input().split())
p = [int(x) for x in input().split()]
p.sort()
test = p[-1] - p[0]
for i in range(0, b - a + 1):
	if p[i + a - 1] - p[i] < test:
		test = p[i + a - 1] - p[i]
print(test)


(m, n) = input().split()
m = int(m)
n = int(n)
list = list(map(int, input().split()))
list.sort()
diffx = list[m - 1] - list[0]
low = 0
high = m - 1
while high < len(list):
	diff = list[high] - list[low]
	if diff < diffx:
		diffx = diff
	low += 1
	high += 1
print(diffx)


import sys
sys.setrecursionlimit(20000)

def getlist(tcast):
	return [tcast(x) for x in input().strip().split(' ')]

def getval(tcast):
	return tcast(input().strip())

def getmatrix(r, tcast):
	mat = []
	for i in range(r):
		mat.append(getlist(tcast))
	return mat
(wsize, n) = getlist(int)
vals = getlist(int)
vals.sort()
mindif = float('inf')
for i in range(n - wsize + 1):
	curdif = vals[wsize - 1 + i] - vals[i]
	mindif = min(mindif, curdif)
print(mindif)


[n, m] = [int(x) for x in input().split()]
o = 99999
l = [int(x) for x in input().split()]
l.sort()
for i in range(m - n + 1):
	if l[i + n - 1] - l[i] < o:
		o = l[i + n - 1] - l[i]
print(o)


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
f.sort()
p = 99999
for i in range(0, m - n + 1):
	k = f[i + n - 1] - f[i]
	p = min(k, p)
print(p)


(n, m) = input().split()
n = int(n)
m = int(m)
best = 1001
listt = list(input().split(' '))
for i in range(len(listt)):
	listt[i] = int(listt[i])
listt.sort()
for i in range(m - n + 1):
	best = min(best, listt[i + n - 1] - listt[i])
print(best)


(n, m) = map(int, input().split())
pieces = list(map(int, input().split()))
pieces.sort()
differences = []
for i in range(m - n + 1):
	differences.append(pieces[i + n - 1] - pieces[i])
differences.sort()
print(differences[0])


(n, m) = map(int, input().split())
ls = list(map(int, input().split()))
ans = sum(ls)
ls.sort(reverse=True)
for i in range(len(ls) - n + 1):
	l1 = ls[i]
	l2 = ls[i + n - 1]
	diff = l1 - l2
	if diff < ans and diff >= 0:
		ans = diff
print(ans)


(m, n) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
a = sorted(a)
ans = 10000
for i in range(n - m + 1):
	if ans > a[i + m - 1] - a[i]:
		ans = a[i + m - 1] - a[i]
print(ans)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
(left, right) = (0, n - 1)
ans = a[right] - a[left]
while right < m:
	ans = min(ans, a[right] - a[left])
	right += 1
	left += 1
print(ans)


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


(n, m) = [int(x) for x in input().split()]
f = [int(x) for x in input().split()]
f = sorted(f)
i = n - 1
a = 0
hasil = []
while i < len(f):
	hasil += [f[i] - f[a]]
	a += 1
	i += 1
print(min(hasil))


import sys
(n, l) = list(map(int, input().strip().split()))
k = list(map(int, input().strip().split()))
maxdiff = sys.maxsize
i = n - 1
k.sort()
while i < l:
	if k[i] - k[i - n + 1] < maxdiff:
		maxdiff = k[i] - k[i - n + 1]
	i += 1
print(maxdiff)


(n, m) = list(map(int, input().split()))
x = list(map(int, input().split()))
x.sort()
min_dif = 1000
for k in range(m - n + 1):
	if abs(x[k] - x[k + n - 1]) < min_dif:
		min_dif = abs(x[k] - x[k + n - 1])
print(min_dif)


n = [int(i) for i in input().split()]
f = [int(i) for i in input().split()]
f.sort()
minim = f[0 + n[0] - 1] - f[0]
for i in range(len(f)):
	if i == len(f) - n[0] + 1:
		break
	if f[i + n[0] - 1] - f[i] < minim:
		minim = f[i + n[0] - 1] - f[i]
print(minim)


(n, m) = map(int, input().split())
pieces = sorted(map(int, input().split()))
diff = []
for i in range(m - n + 1):
	diff.append(pieces[i + n - 1] - pieces[i])
print(min(diff))


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


(studentNum, puzzleNum) = map(int, input().split())
puzzleList = list(map(int, input().split()))
puzzleList.sort()
result = puzzleList[studentNum - 1] - puzzleList[0]
for i in range(1, len(puzzleList) - studentNum + 1):
	a = puzzleList[i]
	b = puzzleList[i + studentNum - 1]
	if b - a < result:
		result = b - a
print(result)


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


(n, m) = input().split()
(n, m) = (int(n), int(m))
temp = input().split()
f = []
for i in range(m):
	f.append(int(temp[i]))
f = sorted(f)
min = f[0] + f[n - 1]
for i in range(len(f) - n + 1):
	if min > f[i + n - 1] - f[i]:
		min = f[i + n - 1] - f[i]
print(min)


(m, n) = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
p = sorted(p)
a = []
for i in range(n - m + 1):
	x = p[i + m - 1] - p[i]
	a.append(x)
print(min(a))


list = [int(x) for x in input().split()]
price = [int(x) for x in input().split()]
price.sort()
print(min([price[i + list[0] - 1] - price[i] for i in range(0, list[1] - list[0] + 1)]))


a = input().split()
a[0] = int(a[0])
a[1] = int(a[1])
b = input().split()
for i in range(len(b)):
	b[i] = int(b[i])
b.sort()
start = 0
min = b[start + (a[0] - 1)] - b[start]
while True:
	if start + (a[0] - 1) > len(b) or start + (a[0] - 1) == len(b):
		break
	else:
		if b[start + (a[0] - 1)] - b[start] < min:
			min = b[start + (a[0] - 1)] - b[start]
		start += 1
print(min)


(n, k) = map(int, input().split())
a = sorted(list(map(int, input().split())))
minim = 1000
for i in range(k - 1):
	for j in range(i + n - 1, k):
		minim = min(minim, abs(a[i] - a[j]))
print(minim)


(n, m) = map(int, input().split())
puzzles = list(map(int, input().split()))
puzzles.sort()
D = puzzles[n - 1] - puzzles[0]
for k in range(1, m - n + 1):
	d = puzzles[n + k - 1] - puzzles[k]
	D = min(d, D)
print(D)


(n, m) = map(int, input().split())
a = [int(i) for i in input().split()]
a.sort()
Mn = 1000
for i in range(m - n + 1):
	Mn = min(Mn, a[i + (n - 1)] - a[i])
print(Mn)


(N, M) = map(int, input().strip().split())
N -= 1
mini = float('inf')
F = list(map(int, input().strip().split()))
F.sort()
for i in range(M - N):
	diff = F[i + N] - F[i]
	mini = min(diff, mini)
print(mini)


s = [int(i) for i in input().split()]
n = s[0]
m = s[1]
s = [int(i) for i in input().split()]
s.sort()
min_difference = 10000000000
if m - n == 0:
	print(s[-1] - s[0])
else:
	for i in range(m - n + 1):
		if s[i + n - 1] - s[i] < min_difference:
			min_difference = s[i + n - 1] - s[i]
	print(min_difference)


import sys
(n, m) = map(int, input().split())
f = list(map(int, input().split()))
f.sort()
diff = 1001
for i in range(m - n + 1):
	(max, min) = (0, 1001)
	for j in range(i, i + n):
		if f[j] < min:
			min = f[j]
		elif f[j] > max:
			max = f[j]
	local_diff = max - min
	if local_diff < diff:
		diff = local_diff
print(diff)


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


def main():
	(s, n) = map(int, input().split(' '))
	puz = list(map(int, input().split(' ')))
	puz.sort()
	min_diff = max(puz)
	for i in range(0, n - s + 1):
		if puz[i + s - 1] - puz[i] < min_diff:
			min_diff = puz[i + s - 1] - puz[i]
	print(min_diff)
main()


(n, m) = map(int, input().split())
pz = list(map(int, input().split()))
pz.sort()
min_dif = 10000
for i in range(n - 1, m):
	if pz[i] - pz[i - n + 1] < min_dif:
		min_dif = pz[i] - pz[i - n + 1]
print(min_dif)


(n, m) = [int(i) for i in input().split(' ')]
f = [int(i) for i in input().split(' ')]
f.sort()
low = f[-1]
if n == m:
	low = f[-1] - f[0]
else:
	for i in range(m - n + 1):
		low = min(low, f[i + n - 1] - f[i])
print(low)


(n, m) = [int(x) for x in input().split()]
fList = [int(x) for x in input().split()]
for i in range(1, m):
	for j in range(i - 1, -1, -1):
		if fList[j + 1] < fList[j]:
			a = fList[j]
			fList[j] = fList[j + 1]
			fList[j + 1] = a
		else:
			break
ans = fList[m - 1] - fList[0]
for i in range(m - n + 1):
	if fList[i + n - 1] - fList[i] < ans:
		ans = fList[i + n - 1] - fList[i]
print(ans)


(n, m) = map(int, input().split())
arr = sorted(list(map(int, input().split())))
k = arr[n - 1] - arr[0]
for i in range(n - 1, m):
	s = arr[i] - arr[i - n + 1]
	if k > s:
		k = s
print(k)


(n, m) = map(int, input().split(' '))
arr = map(int, input().split(' '))
diff = 10000
arr = sorted(arr)
for (k, v) in enumerate(arr):
	if k + n - 1 < len(arr) and arr[k + n - 1] - arr[k] < diff:
		diff = arr[k + n - 1] - arr[k]
print(diff)


(n, m) = [int(i) for i in input().split()]
t = sorted([int(i) for i in input().split()])
mx = 2000
for i in range(m - n + 1):
	q = t[i + n - 1] - t[i]
	if mx > q:
		mx = q
print(mx)


(a, b) = map(int, input().split())
c = sorted(list(map(int, input().split())))
dem = 100000000000
for i in range(b - a + 1):
	khong = max(c[i:i + a]) - min(c[i:i + a])
	dem = min(dem, khong)
print(dem)


def mindif(n, l):
	l.sort()
	(i, j) = (0, n - 1)
	dif = l[j] - l[i]
	while j < len(l):
		dif = min(dif, l[j] - l[i])
		i += 1
		j += 1
	return dif
(n, m) = tuple(map(int, input().split()))
l = list(map(int, input().split()))
print(mindif(n, l))


while 1:
	try:
		(n, m) = map(int, input().split())
		a = list(map(int, input().split()))
		a.sort()
		minimum = a[n - 1] - a[0]
		for i in range(1, len(a) - n + 1):
			if a[i + (n - 1)] - a[i] < minimum:
				minimum = a[i + (n - 1)] - a[i]
		print(minimum)
	except EOFError:
		break


(n, m) = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
p.sort()
mi = p[m - 1] - p[0]
d = 0
for i in range(m - n + 1):
	d = p[i + n - 1] - p[i]
	if d < mi:
		mi = d
print(mi)


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
(n, m) = zz()
l = szzz()
ans = float('inf')
for i in range(n, m + 1):
	ans = min(ans, l[i - 1] - l[i - n])
print(ans)


(students, num_puzzles) = (int(i) for i in input().split())
puzzles = [int(i) for i in input().split()]
puzzles.sort()
lowest = puzzles[-1]
for i in range(0, num_puzzles - students + 1):
	diff = puzzles[i + students - 1] - puzzles[i]
	if diff < lowest:
		lowest = diff
print(lowest)


(n, m) = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
ll = sorted(l)
dif = [1] * (m - n + 1)
for x in range(m):
	if x <= m - n:
		dif[x] = ll[x + n - 1] - ll[x]
print(min(dif))


t = input()
temp = t.split()
n = int(temp[0])
m = int(temp[1])
pieces = input()
temp = pieces.split()
intList = [int(i) for i in temp]
intList.sort()
result = None
for i in range(m):
	if i + (n - 1) > m - 1:
		break
	difference = intList[i + (n - 1)] - intList[i]
	if result is None or difference < result:
		result = difference
print(result)


(x, y) = [int(x) for x in input('').split()]
ar = list(map(int, input().strip().split(' ')))
ar.sort()
z = 10000
for i in range(0, y - x + 1):
	diff = ar[i + x - 1] - ar[i]
	if diff < z:
		z = diff
print(z)


(n, k) = map(int, input().split())
puzzles = list(map(int, input().split()))
puzzles.sort(reverse=True)
a = []
for i in range(k - n + 1):
	a.append(puzzles[i] - puzzles[i + n - 1])
print(min(a))


(n, m) = map(int, input().split())
puzzles = sorted(list(map(int, input().split())))
mindiff = 1001
for i in range(m - n + 1):
	if puzzles[i + n - 1] - puzzles[i] < mindiff:
		mindiff = puzzles[i + n - 1] - puzzles[i]
print(mindiff)


(n, m) = map(int, input().split())
a = sorted(list(map(int, input().split())))
mn = 21482394890
for i in range(m - n + 1):
	mn = min(mn, a[i + n - 1] - a[i])
print(mn)


(stdNum, pzlNum) = map(int, input().split())
puzzle = list(map(int, input().split()))
puzzle.sort()
diff = puzzle[-1]
for i in range(pzlNum - stdNum + 1):
	dif = abs(puzzle[i] - puzzle[i + stdNum - 1])
	if dif < diff:
		diff = dif
print(diff)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
ans = 1000000000000
l.sort()
for i in range(m - (n - 1)):
	x = abs(l[i] - l[i + (n - 1)])
	if x < ans:
		ans = x
print(abs(ans))


(n, m) = map(int, input().split())
pieces = list(map(int, input().split()))
pieces.sort()
if n == m:
	print(pieces[-1] - pieces[0])
else:
	b = []
	for i in range(0, m - n + 1):
		b.append(pieces[n + i - 1] - pieces[i])
	print(min(b))


x = input().split(' ')
n = int(x[0])
m = int(x[1])
x = input().split()
x = [int(i) for i in x]
x = sorted(x)
i = 0
ans = 10000
while i + n - 1 < m:
	ans = min(ans, x[i + n - 1] - x[i])
	i = i + 1
print(ans)


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


(ns, np) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
k = 1000000
for i in range(np - ns + 1):
	k = min(k, l[i + ns - 1] - l[i])
print(k)


(n, m) = map(int, input().split())
f = list(sorted(map(int, input().split())))
i = 0
ans = 100000
while i + n - 1 < len(f):
	ans = min(ans, f[i + n - 1] - f[i])
	i += 1
print(ans)


(n, m) = map(int, input().split())
a = sorted(list(map(int, input().split())))
min1 = 1001
for i in range(m - n + 1):
	if a[i + n - 1] - a[i] < min1:
		min1 = a[i + n - 1] - a[i]
print(min1)


import math
(i, j) = map(int, input().split())
pul = [int(x) for x in input().split()]
pul.sort()
cha = [0] * (j - i + 1)
for k in range(j - i + 1):
	cha[k] = pul[k + i - 1] - pul[k]
print(min(cha))


(n, m) = map(int, input().split())
string = list(map(int, input().split()))
string.sort()
diff = [string[i + n - 1] - string[i] for i in range(m - n + 1)]
print(min(diff))


(n, m) = map(int, input().split())
s = list(map(int, input().split()))
s.sort()
tlist = []
for i in range(m - n + 1):
	t = s[i + n - 1] - s[i]
	tlist.append(t)
tlist.sort()
print(tlist[0])


(n, m) = map(int, input().split())
p = sorted(list(map(int, input().split())))
minimum = 100000
for i in range(m - n + 1):
	minimum = min(minimum, p[i + n - 1] - p[i])
print(minimum)


s = input()
a = s.split()
for i in range(len(a)):
	a[i] = int(a[i])
s = input()
b = s.split()
for i in range(len(b)):
	b[i] = int(b[i])
b.sort()
i = 0
min = b[a[0] - 1] - b[0]
while i < len(b) - a[0] + 1:
	if b[i + a[0] - 1] - b[i] < min:
		min = b[i + a[0] - 1] - b[i]
	i += 1
print(min)


def finMinRange(class_strength, n, nums):
	nums = sorted(nums)
	min_range = nums[n - 1]
	for i in range(n - class_strength + 1):
		min_range = min(min_range, nums[i + class_strength - 1] - nums[i])
	print(min_range)
(class_strength, n) = [int(x) for x in input().split(' ')]
nums = [int(x) for x in input().split(' ')]
finMinRange(class_strength, n, nums)


(n, m) = [int(x) for x in input().split()]
f = sorted([int(x) for x in input().split()])
minimum = 32000
for i in range(m - n + 1):
	minimum = min(minimum, f[i + n - 1] - f[i])
print(minimum)


(n, s) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
mini = float('inf')
for i in range(s - n + 1):
	if l[i + n - 1] - l[i] < mini:
		mini = l[i + n - 1] - l[i]
print(mini)


n = int(input().split(' ')[0])
f = [int(i) for i in input().split(' ')]
f.sort()
minq = 10000
for i in range(0, len(f) - n + 1):
	minq = min(f[i + n - 1] - f[i], minq)
print(minq)


(n, m) = input().split()
n = int(n)
m = int(m)
arr = [int(x) for x in input().split()]
arr.sort(key=None, reverse=False)
min = 100000
for i in range(m - n + 1):
	diff = arr[i + n - 1] - arr[i]
	if diff < min:
		min = diff
print(min)


import sys
(n, m) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
diff = sys.maxsize
a.sort()
j = n - 1
i = 0
while j < m:
	if a[j] - a[i] < diff:
		diff = a[j] - a[i]
	j += 1
	i += 1
print(diff)


n = list(map(int, input().split()))
z = list(map(int, input().split()))
z.sort()
min = 999999
kiri = 0
kanan = kiri + n[0] - 1
while kanan <= n[1] - 1:
	if z[kanan] - z[kiri] < min:
		min = z[kanan] - z[kiri]
	kiri += 1
	kanan = kiri + n[0] - 1
print(min)


info = [int(i) for i in input().split()]
n = info[0]
m = info[1]
f = [int(i) for i in input().split()][:m]
f.sort()
j = n - 1
mini = 3000000000000000000
for x in f:
	if j == m:
		break
	temp = f[j] - x
	mini = min(temp, mini)
	j = j + 1
print(mini)


from sys import stdin

def main():
	n = int(stdin.readline().split()[0])
	l = list(map(int, stdin.readline().split()))
	l.sort()
	print(min((a - b for (a, b) in zip(l[n - 1:], l))))
main()


(a, b) = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
m = 0
n = 99999999999
for i in range(0, b - a + 1):
	m = c[i + a - 1] - c[i]
	n = min(m, n)
print(n)


(a, b) = map(int, input().split())
x = [int(x) for x in input().split()]
x.sort()
l = []
d = 0
s = []
for i in range(b - a + 1):
	j = i
	while j <= i + a - 1:
		l.append(x[j])
		j += 1
	s.append(max(l) - min(l))
	l = []
print(min(s))


inp = input().split()
n = int(inp[0])
m = int(inp[1])
ar = input().split()
for i in range(len(ar)):
	ar[i] = int(ar[i])
ar = sorted(ar)
mi = [0] * (m + 1 - n)
for i in range(m + 1 - n):
	mi[i] = ar[i + n - 1] - ar[i]
print(min(mi))


d = [int(x) for x in input().split()]
p = [int(y) for y in input().split()]
p.sort()
mi = -1
for i in range(len(p) - d[0] + 1):
	l = p[i:i + d[0]]
	diff = l[-1] - l[0]
	if mi == -1 or diff < mi:
		mi = diff
print(mi)


(N, M) = map(int, input().split())
F = list(map(int, input().split()))
F.sort()
min_delta = 1001
for i in range(M - N + 1):
	min_delta = min(F[i + N - 1] - F[i], min_delta)
print(min_delta)


num = []
num = list(map(int, input().split()))
pieces = list(map(int, input().split()))
pieces.sort()
a = pieces[num[0] - 1] - pieces[0]
for i in range(num[1] - num[0] + 1):
	if pieces[i + num[0] - 1] - pieces[i] < a:
		a = pieces[i + num[0] - 1] - pieces[i]
print(a)


(n, m) = map(int, input().split())
arr = [int(x) for x in input().split()]
arr.sort()
i = 0
min = 1000
while i <= int(m) - n:
	if arr[i + n - 1] - arr[i] < min:
		min = arr[i + n - 1] - arr[i]
	i = i + 1
print(min)


import sys
(n, m) = [int(x) for x in sys.stdin.readline().strip().split()]
fs = [int(x) for x in sys.stdin.readline().strip().split()]
fs.sort()
min_diff = float('inf')
for i in range(len(fs) - n + 1):
	diff = fs[i + n - 1] - fs[i]
	min_diff = min(diff, min_diff)
print(min_diff)


(n, m) = [int(x) for x in input().split()]
f = [int(x) for x in input().split()]
f.sort()
min_val = 1000
for x in range(m - n + 1):
	min_val = min(min_val, f[x + n - 1] - f[x])
print(min_val)


(n, m) = map(int, input().split())
differ = []
minimum = []
size = sorted(list(map(int, input().split())))
for i in range(len(size) - 1):
	differ.append(size[i + 1] - size[i])
for i in range(0, m - n + 1):
	summ = 0
	j = 0
	while j < n - 1:
		summ += differ[i + j]
		j += 1
	minimum.append(summ)
print(min(minimum))


import math
(n, k) = input().split()
n = int(n)
k = int(k)
a = input().split()
for i in range(k):
	a[i] = int(a[i])
a.sort()
min_div = a[n - 1] - a[0]
for i in range(1, k - n + 1):
	min_div = min(a[i + n - 1] - a[i], min_div)
print(min_div)


L1 = input().split()
n = int(L1[0])
m = int(L1[1])
L = input().split()
L = [int(i) for i in L]
L.sort()
min_dif = L[n - 1] - L[0]
for i in range(1, m - n + 1):
	x = L[n + i - 1] - L[i]
	if x < min_dif:
		min_dif = x
print(min_dif)


students = [int(n) for n in input().split(' ')][0]
puzzles = sorted([int(n) for n in input().split(' ')])
min_diff = 1000
for i in range(len(puzzles) - students + 1):
	l = puzzles[i:i + students]
	if max(l) - min(l) < min_diff:
		min_diff = max(l) - min(l)
print(min_diff)


from heapq import heappush, heappop
import queue
import re
import math
import functools

def int_raw():
	return int(input())

def ss_raw():
	return input().split()

def ints_raw():
	return list(map(int, ss_raw()))
INF = 1 << 29

def make1d_arr(n, val=INF):
	return [val for i in range(n)]

def make2d_arr(h, w, val=INF):
	return [[val for i in range(w)] for i in range(h)]

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
(N, M) = ints_raw()
Fs = ints_raw()

def main():
	Fs.sort()
	ans = Fs[N - 1] - Fs[0]
	for f_idx in range(N, M):
		ans = min(ans, Fs[f_idx] - Fs[f_idx - N + 1])
	return ans
print(main())


(n, m) = map(int, input().split())
li = list(map(int, input().split()))
li.sort()
li2 = []
for i in range(m):
	if i + n > m:
		break
	try:
		li1 = list(li[i:i + n])
		li2.append(max(li1) - min(li1))
	except IndexError:
		break
print(min(li2))


while True:
	try:
		(n, m) = list(map(int, input().split()))
		A = list(map(int, input().split()))
		A.sort()
		ans = A[n - 1] - A[0]
		for i in range(1, m - n + 1):
			ans = min(ans, A[i + n - 1] - A[i])
		print(ans)
	except EOFError:
		break


from sys import stdin, stdout
from math import inf

def main():
	(n, m) = map(int, stdin.readline().split())
	puzzels = sorted(map(int, stdin.readline().split()))
	minimum_value = inf
	for index in range(m - n + 1):
		diff = puzzels[index + n - 1] - puzzels[index]
		minimum_value = min(minimum_value, diff)
	stdout.write(f'{minimum_value}\n')
main()


(people, puzzle) = [int(x) for x in input().split()]
list = [int(y) for y in input().split()]
list.sort()
list1 = []
for i in range(puzzle - people + 1):
	k = list[i + people - 1] - list[i]
	list1.append(k)
list1.sort()
print(list1[0])


(n, m) = map(int, input().split())
f = [int(i) for i in input().split()]
f = sorted(f)
minimum = f[n - 1] - f[0]
for i in range(1, m - n + 1):
	if f[i + n - 1] - f[i] < minimum:
		minimum = f[i + n - 1] - f[i]
print(minimum)


(n, m) = map(int, input().split())
f = [int(ch) for ch in input().split()]
f = sorted(f)
res = 2000
for i in range(m - n + 1):
	diff = f[i + n - 1] - f[i]
	res = min(diff, res)
if m - n == 0:
	res = f[n - 1] - f[0]
print(res)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = -1
mid = 0
for i in range(0, m - n + 1):
	mid = a[i + n - 1] - a[i]
	if mid < ans or ans == -1:
		ans = mid
print(ans)


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


x = [int(x) for x in input().split()]
y = [int(x) for x in input().split()]
n = x[0]
m = x[1]
a = 0
b = []
y.sort()
while a + n <= m:
	b.append(y[a + n - 1] - y[a])
	a = a + 1
print(min(b))


(n, m) = input().split()
n = int(n)
m = int(m)
num_pieces = list(map(int, input().split()))
num_pieces.sort()
maxab = 10000
for i in range(m - n + 1):
	ab = num_pieces[i + n - 1] - num_pieces[i]
	if ab < maxab:
		maxab = ab
print(maxab)


from itertools import *
(n, m) = map(int, input().split())
mi = None
l = list(map(int, input().split()))
l.sort()
for i in range(len(l) - n + 1):
	if mi is None:
		mi = max(l[i:i + n]) - min(l[i:i + n])
	elif mi > max(l[i:i + n]) - min(l[i:i + n]):
		mi = max(l[i:i + n]) - min(l[i:i + n])
print(mi)


(n, m) = [int(i) for i in input().split(' ')]
jig = sorted([int(i) for i in input().split(' ')])
amin = 1000
for i in range(m - n + 1):
	if jig[i + n - 1] - jig[i] < amin:
		amin = jig[i + n - 1] - jig[i]
print(amin)


import sys
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
a.insert(0, 0)
res = sys.maxsize
for i in range(1, m - n + 2):
	minn = sys.maxsize
	maxx = -sys.maxsize
	for j in range(i, i + n):
		minn = min(minn, a[j])
		maxx = max(maxx, a[j])
	res = min(res, maxx - minn)
print(res)


a = list(map(int, input().split()))
(n, m) = (a[0], a[1])
lst = sorted(list(map(int, input().split())))
diff = 100000
for i in range(m - n + 1):
	diff = min(lst[i + n - 1] - lst[i], diff)
print(diff)


def main(n, m, lst):
	lst = sorted(lst)
	minn = float('inf')
	for i in range(m - n + 1):
		minn = min(minn, lst[i + n - 1] - lst[i])
	return minn
(n, m) = [int(x) for x in input().split()]
lst = list(map(int, input().split()))
print(main(n, m, lst))


def resolve(n, lista):
	lista = sorted(lista)
	menor = 9999999999
	for i in range(len(lista) - n + 1):
		sub = lista[i + n - 1] - lista[i]
		if sub < menor:
			menor = sub
	return menor
(n, m) = [int(i) for i in input().split(' ')]
lista = [int(i) for i in input().split(' ')]
print(resolve(n, lista))


(n, m) = map(int, input().split())
st = input()
lst = st.split()
for i in range(0, len(lst)):
	lst[i] = int(lst[i])
lst1 = sorted(lst)
least = lst1[n - 1] - lst1[0]
for i in range(1, m - n + 1):
	if lst1[i + n - 1] - lst1[i] < least:
		least = lst1[i + n - 1] - lst1[i]
print(least)


m = list(input().split())
p = int(m[1])
s = int(m[0])
pl = list(map(int, input().split()))
pl = sorted(pl)
diff = max(pl)
x = 0
while x + s - 1 < p:
	if diff > pl[x + s - 1] - pl[x]:
		diff = pl[x + s - 1] - pl[x]
	x += 1
print(diff)


def main():
	(nb, x) = map(int, input().split())
	tab = list(map(int, input().split()))
	tab.sort()
	mini = 1000 * 1000
	nb -= 1
	for i in range(x - nb):
		mini = min(mini, tab[i + nb] - tab[i])
	print(mini)
main()


(n, m) = map(int, input().split(' '))
li = list(map(int, input().split(' ')))
var = 100000000000000
li.sort()
j = 0
for i in li[:m - n + 1]:
	x = li[j:j + n]
	if max(x) - min(x) < var:
		var = max(x) - min(x)
	j += 1
if var == 100000000000000:
	print(0)
else:
	print(var)


(n, m) = [int(i) for i in input().split()]
k = [int(j) for j in input().split()]
newk = sorted(k)
cha = abs(newk[m - 1] - newk[0])
for p in range(n - 1, m):
	if newk[p] - newk[p - n + 1] < cha:
		cha = newk[p] - newk[p - n + 1]
print(cha)


(n, m) = map(int, input().split())
l = sorted(list(map(int, input().split())))
c = []
for x in range(m - n + 1):
	c.append(l[x + n - 1] - l[x])
print(min(c))


(a, b) = map(int, input().split())
l = sorted(list(map(int, input().split())))
ans = 100000000
for i in range(b - a + 1):
	ans = min(l[i + a - 1] - l[i], ans)
print(ans)


(n, m) = map(int, input().split())
s = sorted(list(map(int, input().split())))
t = []
for i in range(m - n + 1):
	p = s[i + n - 1] - s[i]
	t = t + [p]
j = sorted(t)
print(j[0])


(n, m) = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]
q.sort()
ans = int(100000.0)
for i in range(len(q) - n + 1):
	newq = q[i:i + n]
	ans = min(ans, max(newq) - min(newq))
print(ans)


def puzz_diff(a, n):
	a.sort()
	diff = []
	for i in range(0, len(a) - n + 1):
		diff.append(a[i + n - 1] - a[i])
	print(min(diff))
s = input().split()
n = int(s[0])
a = list(map(int, input().split(' ')))
puzz_diff(a, n)


(n, m) = map(int, input().split())
s = list(map(int, input().split()))
s.sort()
min = 1000000000000
for i in range(m - n + 1):
	q = s[i + n - 1] - s[i]
	if q < min:
		min = q
print(min)


(n, m) = map(int, input().split())
puzzles = sorted(map(int, input().split()))
diff = 1000
for i in range(len(puzzles) - n + 1):
	a = i
	b = i + n - 1
	d = min(puzzles[a:b + 1])
	e = max(puzzles[a:b + 1])
	c = e - d
	if c < diff:
		diff = c
print(diff)


def findMin(a, b):
	if a >= b:
		return b
	else:
		return a
(students, puzzles) = [int(x) for x in input().split(' ')]
pieces = [int(x) for x in input().split(' ')]
pieces.sort()
min = 999999999
i = 0
while i <= puzzles - students:
	if min > pieces[i + students - 1] - pieces[i]:
		min = pieces[i + students - 1] - pieces[i]
	i += 1
print(min)


(n, m) = map(int, input().split(' '))
pieces = list(map(int, input().split(' ')))
pieces.sort()
diffs = [pieces[i + n - 1] - pieces[i] for i in range(0, len(pieces) - n + 1)]
print(min(diffs))


n = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
min1 = a[n[0] - 1] - a[0]
for i in range(n[1] - n[0] + 1):
	min1 = min(a[n[0] - 1 + i] - a[i], min1)
print(min1)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
a.reverse()
b = []
for i in range(m):
	for j in range(i + (n - 1), m):
		b.append(a[i] - a[j])
b.sort()
print(b[0])


from sys import stdin, stdout
nm = list(map(int, stdin.readline().strip().split()))
n = nm[0]
m = nm[1]
piece_list = list(map(int, stdin.readline().split()))
piece_list.sort()
min_diff = piece_list[n - 1] - piece_list[0]
for k in range(m + 1 - n):
	min_diff = min(min_diff, piece_list[k + n - 1] - piece_list[k])
stdout.write(str(min_diff))


import sys

def puz():
	line1 = sys.stdin.readline().split(' ')
	if line1[-1] == '\n':
		line1.pop()
	else:
		line1[-1].rstrip()
	puzz_num = int(line1[0])
	total = int(line1[1])
	puzzs = sys.stdin.readline().split(' ')
	if line1[-1] == '\n':
		puzzs.pop()
	else:
		puzzs[-1].rstrip()
	puzzs = [int(x) for x in puzzs]
	puzzs.sort()
	start = 0
	end = puzz_num - 1
	local_min = None
	smallest = None
	while end < total:
		local_min = puzzs[end] - puzzs[start]
		if smallest is None:
			smallest = local_min
		elif local_min < smallest:
			smallest = local_min
		start += 1
		end += 1
	return smallest
print(puz())


input_str = input().split(' ')
n = int(input_str[0])
m = int(input_str[1])
input_str = input().split(' ')
array = []
for i in input_str:
	array.append(int(i))
array.sort()
min = 1000
for i in range(m - n + 1):
	current_min = array[i + n - 1] - array[i]
	if min > current_min:
		min = current_min
print(min)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
ans = 0
mina = float('inf')
for i in range(0, m - n + 1):
	ans = abs(a[i] - a[i + n - 1])
	if mina > ans:
		mina = ans
print(mina)


(n, m) = (int(x) for x in input().split())
pieces = [int(x) for x in input().split()]
pieces.sort()
min_p = 10000000
for i in range(m - n + 1):
	dif = pieces[i + n - 1] - pieces[i]
	min_p = min(min_p, dif)
print(min_p)


def main():
	(n, m) = tuple(map(int, input().rstrip().split()))
	A = sorted(map(int, input().rstrip().split()))
	ans = float('inf')
	for i in range(m - n + 1):
		ans = min(ans, A[i + n - 1] - A[i])
	print(ans)
main()


def func(n):
	x = list(map(int, input().split()))
	x.sort()
	count = 0
	maxi = x[0 + n[0] - 1] - x[0]
	for i in range(len(x) - n[0] + 1):
		count = x[i + n[0] - 1] - x[i]
		if count < maxi:
			maxi = count
	print(maxi)
n = list(map(int, input().split()))
func(n)


(m, n) = map(int, input().strip().split())
qn = list(map(int, input().strip().split()))
qn.sort()
ans = 1000000000.0
for i in range(0, n - m + 1):
	ans = min(ans, int(qn[i + m - 1]) - int(qn[i]))
print(ans)


(a, b) = input().split()
a = int(a)
b = int(b)
alist = list(map(int, input().split()))
alist.sort()
i = 0
diff = 0
mini = 1000
while i < b - a + 1:
	diff = alist[i + a - 1] - alist[i]
	mini = min(mini, diff)
	i += 1
print(mini)


input_s = input().split(' ')
s_m = int(input_s[0])
input_l = input().split(' ')
list_l = []
for l in input_l:
	list_l.append(int(l))
for i in range(len(list_l)):
	for j in range(i + 1, len(list_l)):
		if list_l[i] > list_l[j]:
			(list_l[i], list_l[j]) = (list_l[j], list_l[i])
min_AB = 9999
for i in range(len(list_l) - s_m + 1):
	min_AB = min(list_l[i + s_m - 1] - list_l[i], min_AB)
print(min_AB)


(n, m) = input().split()
n = int(n)
m = int(m)

def intmaker(arr):
	for i in range(len(arr)):
		arr[i] = int(arr[i])
	return arr
puzzles = intmaker(input().split())
puzzles = sorted(puzzles)
diff = max(puzzles[0:n]) - min(puzzles[0:n])
i = 0
while n <= len(puzzles):
	if max(puzzles[i:n]) - min(puzzles[i:n]) < diff:
		diff = max(puzzles[i:n]) - min(puzzles[i:n])
	i += 1
	n += 1
print(diff)


(n, m) = [int(x) for x in input().split()]
f = [int(x) for x in input().split()]
f.sort()
d = []
for i in range(m - n + 1):
	d.append(f[n + i - 1] - f[i])
print(min(d))


(n, m) = map(int, input().split(' '))
l = list(map(int, input().split(' ')))
l.sort()
differences = []
i = 0
while i + n - 1 < m:
	differences.append(l[i + n - 1] - l[i])
	i += 1
print(min(differences))


import sys
import math
(n, m) = map(int, input().split())
s = list(map(int, input().split()))
s = sorted(s)
ans = 1000000000000
for i in range(m - n + 1):
	ans = min(ans, s[i + n - 1] - s[i])
print(ans)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
if n == m:
	print(a[-1] - a[0])
else:
	ans = float('inf')
	for i in range(0, m - n + 1):
		ans = min(ans, a[n + i - 1] - a[i])
	print(ans)


(a, b) = map(int, input().split())
c = sorted(map(int, input().split()))
print(min((c[i + a - 1] - c[i] for i in range(b - a + 1))))


(n, m) = [int(i) for i in input().split()]
f = [int(i) for i in input().split()]
f = sorted(f)
n1 = n - 1
m = m - 1
minimum = f[n1] - f[0]
n1 = n1 + 1
while n1 <= m:
	k = f[n1] - f[n1 - n + 1]
	if k < minimum:
		minimum = k
	n1 = n1 + 1
print(minimum)


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
max_pres = 1000000000
min_pres = -1000000000
least_diff = 1000000000
for i in range(0, len(f) - 1):
	for j in range(i + 1, len(f)):
		if abs(f[i] - f[j]) < least_diff:
			accepted_pres = 0
			for k in range(0, len(f)):
				if min(f[i], f[j]) <= f[k] <= max(f[i], f[j]):
					accepted_pres = accepted_pres + 1
			if accepted_pres >= n:
				least_diff = abs(f[i] - f[j])
print(least_diff)


(n, m) = input().split()
(n, m) = (int(n), int(m))
f = [int(i) for i in input().split()]
f.sort()
least = max(f) - min(f)
for k in range(m - n + 1):
	least = min(least, f[k + n - 1] - f[k])
print(least)


(n, m) = input().split()
(n, m) = (int(n), int(m))
fs = input().split()
fs = [int(f) for f in fs]
fs.sort()
distance = 0
for i in range(m - n + 1):
	if distance == 0 and i == 0 or fs[i + n - 1] - fs[i] < distance:
		distance = fs[i + n - 1] - fs[i]
print(distance)


(n, m) = input().split()
n = int(n)
m = int(m)
a = m - n + 1
x = [int(x) for x in input().split()]
best = 1001
x.sort()
for i in range(a):
	if max(x[i:i + n]) - min(x[i:i + n]) < best:
		best = max(x[i:i + n]) - min(x[i:i + n])
print(best)


(n, m) = map(int, input().split())
l = sorted(list(map(int, input().split())))
ans = 1000000.0
for i in range(m - n + 1):
	if l[n - 1 + i] - l[i] < ans:
		ans = l[n - 1 + i] - l[i]
print(ans)


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
a.sort()
m = 1 << 31
for i in range(0, k - n + 1):
	m = min(m, abs(a[i + n - 1] - a[i]))
print(m)


(ppl, p) = map(int, input().split())
a = [int(i) for i in input().split()]
a = sorted(a)
minn = 99999999999999999
(i, j) = (0, ppl - 1)
while j < len(a):
	d = a[j] - a[i]
	if d < minn:
		minn = d
	i += 1
	j += 1
print(minn)


l = lambda : map(int, input().split())
(n, m) = l()
arr = sorted(list(l()))
min = arr[-1]
for i in range(m - n + 1):
	if arr[i + n - 1] - arr[i] < min:
		min = arr[i + n - 1] - arr[i]
print(min)


(n, m) = input().split()
(n, m) = (int(n), int(m))
l = list(map(int, input().split()))
l.sort()
diff = 2 ** 31
for i in range(0, m):
	for j in range(i + (n - 1), m):
		diff = min(l[j] - l[i], diff)
print(diff)


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()

def findMin(arr, n, m):
	if n == m:
		return arr[-1] - arr[0]
	i = n
	min_sum = 10 ** 9
	sum = 0
	while i <= m:
		sum = arr[i - 1] - arr[i - n]
		if sum <= min_sum:
			min_sum = sum
		i += 1
	return min_sum
print(findMin(arr, n, m))


(n, m) = [int(x) for x in input().split()]
x = sorted([int(x) for x in input().split()])
print(min((j - i for (i, j) in zip(x, x[n - 1:]))))


def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())

def solve():
	(N, M) = getInts()
	F = getInts()
	F.sort()
	best = 10 ** 9
	for i in range(M - N + 1):
		best = min(best, abs(F[i + N - 1] - F[i]))
	return best
ans = solve()
print(ans)


import math
(n, m) = map(int, input().split())
s = [int(x) for x in input().split()]
s = sorted(s)
s1 = []
if n == m:
	print(s[-1] - s[0])
else:
	for i in range(m - n + 1):
		s1.append(s[i + n - 1] - s[i])
	print(min(s1))


import math
from typing import List

def find_local_min(data: 'List[int]', acc: 'int', limit: 'int') -> 'int':
	local_min = data[limit - 1] - data[0] if len(data) >= limit else math.inf
	return acc if not data else find_local_min(data[1:], acc, limit) if local_min > acc else find_local_min(data[1:], local_min, limit)

def main():
	[children, _] = input().split(' ')
	puzzles = [int(x) for x in input().split(' ')]
	print(find_local_min(sorted(puzzles), math.inf, int(children)))
main()


(n, m) = map(int, input().split())
f = sorted(list(map(int, input().split())))
dif = []
for (a, b) in zip(range(m - n + 1), range(n - 1, m)):
	dif.append(f[b] - f[a])
print(min(dif))


(n, m) = input().split()
n = int(n)
m = int(m)
f = [int(i) for i in input().split()]
f.sort()
f.reverse()
min = 9999999999999
for i in range(m - n + 1):
	if f[i] - f[i + n - 1] < min and f[i] - f[i + n - 1] >= 0:
		min = f[i] - f[i + n - 1]
print(min)


a = list(map(int, input().split()))
b = list(map(int, input().split()))
b.sort()
y = 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
for i in range(len(b) - a[0] + 1):
	x = b[i:i + a[0]]
	if y > max(x) - min(x):
		y = max(x) - min(x)
print(y)


s = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
l.sort()
min = 1000000000
for i in range(s[1] - s[0] + 1):
	if l[i + s[0] - 1] - l[i] < min:
		min = l[i + s[0] - 1] - l[i]
print(min)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
mi = max(l[0:n]) - min(l[0:n])
for f1 in range(m - n + 1):
	if mi > max(l[f1:f1 + n]) - min(l[f1:f1 + n]):
		mi = max(l[f1:f1 + n]) - min(l[f1:f1 + n])
print(mi)


args = [int(arg) for arg in input().strip().split(' ')]
(n, m) = (args[0], args[1])
puzzles = [int(arg) for arg in input().strip().split(' ')]
puzzles = sorted(puzzles)
ans = puzzles[m - 1] - puzzles[0]
for i in range(n - 1, m):
	diff = puzzles[i] - puzzles[i - (n - 1)]
	ans = min(ans, diff)
print(ans)


(m, n) = map(int, input().split())
s = list(map(int, input().split()))
s.sort()
best = 10000
for i in range(n - m + 1):
	best = min(best, s[i + m - 1] - s[i])
print(best)


j = input().split()
k = input().split()
numPeople = int(j[0])
for i in range(0, len(k)):
	k[i] = int(k[i])
numPeople -= 1
k = sorted(k)
minDistance = 100000000000
for i in range(0, len(k) - numPeople):
	if k[i + numPeople] - k[i] < minDistance:
		minDistance = k[i + numPeople] - k[i]
print(minDistance)


(n, m) = [int(x) for x in input().split()]
a = [int(o) for o in input().split()]
a.sort()
ma = a[-1] - a[0]
for i in range(m - n + 1):
	c = a[i + n - 1] - a[i]
	ma = min(ma, c)
print(ma)


def main():
	(n, m) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	if n == m:
		print(max(arr) - min(arr))
		return 0
	arr.sort()
	if n == m - 1:
		print(min(arr[-1] - arr[1], arr[-2] - arr[0]))
		return 0
	mi = 9999999999999999
	i = 0
	for i in range(m - n + 1):
		mi = min(arr[i + n - 1] - arr[i], mi)
		i += 1
	print(mi)
	return 0
main()


(p, q) = input().split()
p = int(p)
q = int(q)
a = [int(x) for x in input().split()]
a.sort()
dif = a[p - 1] - a[0]
for i in range(p, q):
	dif = min(dif, a[i] - a[i - p + 1])
print(dif)


l = list(map(int, input().split(' ')))
n = l[0]
m = l[1]
a = list(map(int, input().split(' ')))
a.sort()
b = max(a)
for i in range(0, m - n + 1):
	total = a[i + (n - 1)] - a[i]
	if total < b:
		b = total
print(b)


z = [int(x) for x in input().split()]
f = [int(x) for x in input().split()]
f = sorted(f)
value = list()
for index in range(z[1] - z[0] + 1):
	value.append(f[index + z[0] - 1] - f[index])
print(min(value))


(n, m) = map(int, input().split())
l = [int(x) for x in input().split()]
l.sort()
a = 99999
for i in range(m - n + 1):
	l1 = l[i:i + n]
	if max(l1) - min(l1) < a:
		a = max(l1) - min(l1)
print(a)


(n, m) = map(int, input().split())
mylist = list(map(int, input().split()))
mylist.sort()
i = 0
j = n - 1
ans = 100000000
while j < m:
	ans = min(ans, mylist[j] - mylist[i])
	i += 1
	j += 1
print(ans)


(n, f) = map(int, input().split())
l = list(map(int, input().split()))
l = sorted(l)
t = 0
r = 10001

def maxi(l):
	return max(l) - min(l)
while t + n <= f:
	r = min(r, maxi(l[t:t + n]))
	t += 1
print(r)


(n, m) = map(int, input().split())
lt = sorted(list(map(int, input().split())))
x = lt[n - 1] - lt[0]
for i in range(m - n):
	x = min(x, lt[n + i] - lt[i + 1])
print(x)


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


(n, m) = map(int, input().split())
l = sorted(list(map(int, input().split())))
i = 0
j = n - 1
m = 2 ** 31 - 1
while j < len(l):
	m = min(m, l[j] - l[i])
	i = i + 1
	j = j + 1
print(m)


(n, m) = map(int, input().split())
A = sorted(list(map(int, input().split())))
ans = 100000
for i in range(m - n + 1):
	ans = min(max(A[i:n + i]) - min(A[i:n + i]), ans)
print(ans)


(n, m) = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
C = []
if m == n:
	print(max(A) - min(A))
else:
	for i in range(m - n + 1):
		B = [A[j] for j in range(i, i + n)]
		a = max(B)
		b = min(B)
		C.append(a - b)
	print(min(C))


def Puzzles(n, m, piecesCount):
	piecesCount.sort()
	i = 0
	minDiff = piecesCount[n + i - 1] - piecesCount[i]
	i = 1
	while i <= m - n:
		diff = piecesCount[n + i - 1] - piecesCount[i]
		if diff < minDiff:
			minDiff = diff
		i += 1
	return minDiff
(n, m) = [int(x) for x in input().split()]
nums = [int(x) for x in input().split()]
print(Puzzles(n, m, nums))


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
an = A[n - 1] - A[0]
x = n - 1
while n < len(A):
	an = min(A[n] - A[n - x], an)
	n += 1
print(an)


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
f.sort()
r = []
if n == m:
	print(f[n - 1] - f[0])
else:
	for i in range(len(f) - n + 1):
		r.append(f[i + n - 1] - f[i])
	print(min(r))


(n, m) = [int(x) for x in input().split(' ')]
puzzles = [int(x) for x in input().split(' ')]
puzzles.sort()
minPuzz = 99999
for i in range(n - 1, len(puzzles)):
	if puzzles[i] - puzzles[i - n + 1] < minPuzz:
		minPuzz = puzzles[i] - puzzles[i - n + 1]
print(minPuzz)


from collections import defaultdict as dd

def lcm(a, b):
	return a * b // gcd(a, b)

def inin():
	return int(input())

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

def ar(element, size):
	return [element for i in range(size)]

def digitsum(num):
	su = 0
	while num:
		su += num % 10
		num //= 10
	return su

def yes():
	print('YES')

def no():
	print('NO')

def countDivisibles(A, B, M):
	if A % M == 0:
		return B // M - A // M + 1
	return B // M - A // M

def countSetBits(n):
	count = 0
	while n:
		count += n & 1
		n >>= 1
	return count
Testcase = 1
for _ in range(Testcase):
	(m, n) = inar()
	arr = inar()
	arr.sort()
	i = 0
	df = float('inf')
	m -= 1
	while m < n:
		df = min(df, arr[m] - arr[i])
		i += 1
		m += 1
	print(df)


(n, m) = map(int, input().split())
lis = list(map(int, input().split()))
lis.sort()
minn = 100000
for i in range(m - n + 1):
	if lis[i + n - 1] - lis[i] < minn:
		minn = lis[i + n - 1] - lis[i]
print(minn)


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


from math import *
sInt = lambda : int(input())
mInt = lambda : map(int, input().split())
lInt = lambda : list(map(int, input().split()))
(n, m) = mInt()
a = lInt()
a.sort()
b = []
for i in range(m - n + 1):
	b.append(max(a[i:i + n]) - min(a[i:i + n]))
print(min(b))


(m, n) = map(int, input().split())
a = list(map(int, input().strip().split()))[:n]
a = sorted(a)
dif = a[m - 1] - a[0]
for i in range(len(a) - m + 1):
	x = a[i + m - 1] - a[i]
	if x < dif:
		dif = x
print(dif)


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
mini = 1000000000000000
for i in range(m):
	if i + n - 1 < m:
		mini = min(mini, arr[i + n - 1] - arr[i])
	else:
		break
print(mini)


(n, m) = [int(i) for i in input().split()]
numbers = [int(i) for i in input().split()]
numbers.sort()

def dif_upto_n(numbers, start_index, n):
	new_list = []
	for i in range(start_index, start_index + n):
		new_list.append(numbers[i])
	maxi = max(new_list)
	mini = min(new_list)
	return maxi - mini
index = 0
global_minima = dif_upto_n(numbers, 0, n)
while index <= m - n:
	local_minima = dif_upto_n(numbers, index, n)
	if local_minima < global_minima:
		global_minima = local_minima
	index += 1
print(global_minima)


(d, b) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
a.sort()
a1 = list()
for i in range(len(a)):
	if i <= len(a) - d:
		a1.append(a[d - 1 + i] - a[i])
a1.sort()
for i in range(len(a1)):
	if a.count(a[i]) >= d:
		print(0)
		exit()
print(a1[0])


(n, m) = list(map(int, input().split()))
A = []
A = list(map(int, input().split()))
A.sort()
B = []
for i in range(m - n + 1):
	B.append(A[n - 1 + i] - A[i])
B.sort()
print(B[0])


(n, m) = map(int, input().split())
l = [int(x) for x in input().split()]
l.sort()
ans = 100000000000000
i = 0
while i <= m - n:
	ans = min(ans, l[n + i - 1] - l[i])
	i += 1
print(ans)


import sys
(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
diff = sys.maxsize
for i in range(m - n + 1):
	diff = min(diff, arr[i + n - 1] - arr[i])
print(diff)


(n, m) = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
l.sort()
s = []
for i in range(m - n + 1):
	a = l[i + n - 1]
	b = l[i]
	d = a - b
	s.append(d)
print(min(s))


(n, p) = map(int, input().split())
px = list(map(int, input().split()))
diff = []
px.sort()
for i in range(p - 1):
	diff.append(px[i + 1] - px[i])
sum = []
i = 0
while i < p - n + 1:
	k = 0
	for j in range(n - 1):
		k += diff[i + j]
	sum.append(k)
	i += 1
sum.sort()
print(sum[0])


(n, m) = map(int, input().split())
lst = list(map(int, input().split()))
lst.sort()
t = lst[:n]
dif = t[-1] - t[0]
for i in range(1, m - n + 1):
	x = lst[i:n + i]
	ndif = x[-1] - x[0]
	if dif > ndif:
		dif = ndif
print(dif)


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


(n, m) = map(int, input().split())
f = sorted(list(map(int, input().split())))
qmx = 999999999
for i in range(len(f) - n + 1):
	h = n + i
	q = max(f[i:h]) - min(f[i:h])
	if q < qmx:
		qmx = q
print(qmx)


def find_smallest_interval(num, num_list):
	num_list.sort()
	min_diff = float('inf')
	if num == len(num_list):
		return num_list[-1] - num_list[0]
	for i in range(len(num_list) - num + 1):
		if num_list[i + num - 1] - num_list[i] < min_diff:
			min_diff = num_list[i + num - 1] - num_list[i]
	return min_diff
(num_to_buy, total_num) = input().split()
quantity_list = list(map(int, input().split()))
print(find_smallest_interval(int(num_to_buy), quantity_list))


a = []
(n, m) = map(int, input().split())
a = [int(i) for i in input().split()]
a.sort()
minn = 1000000000.0
for i in range(m - n + 1):
	if a[i + n - 1] - a[i] < minn:
		minn = a[i + n - 1] - a[i]
print(minn)


(n, m) = map(int, input().split())
data = list(map(int, input().split()))
data.sort()
best = 10 ** 4
for i in range(m - n + 1):
	best = min(best, data[i + n - 1] - data[i])
print(best)


(a, b) = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
l.sort()
c = 1e+101
for i in range(b - a + 1):
	if l[i + a - 1] - l[i] < c:
		c = l[i + a - 1] - l[i]
print(c)


n = int(input().split(' ')[0])
f = [int(i) for i in input().split(' ')]
f.sort()
r = 1000
if n == len(f):
	r = f[len(f) - 1] - f[0]
n -= 1
for i in range(len(f) - n):
	r = min(r, f[i + n] - f[i])
print(r)


(m, n) = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
x = A[-1] - A[0]
for i in range(n - m + 1):
	if x > A[i + m - 1] - A[i]:
		x = A[i + m - 1] - A[i]
print(x)


s = [int(n) for n in input().split()]
z = [int(n) for n in input().split()]
z.sort()
z = z[::-1]
k = []
m = []
for n in range(s[1] - s[0] + 1):
	k.append(z[n:n + s[0]])
	m.append(max(k[n]) - min(k[n]))
print(min(m))


(n, m) = map(int, input().strip().split())
puzzles = sorted(list(map(int, input().strip().split())))
best = puzzles[-1]
i = n - 1
while i < m:
	diff = puzzles[i] - puzzles[i - n + 1]
	if diff < best:
		best = diff
	i += 1
print(best)


(a, b) = map(int, input().split())
x = list(map(int, input().split()))
listselisih = []
x.sort()
x.reverse()
if a == b:
	print(x[0] - x[-1])
else:
	for z in range(b - a + 1):
		selisih = x[z] - x[z + a - 1]
		listselisih.append(selisih)
	print(min(listselisih))


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


(n, _) = map(int, input().split())
n -= 1
min_difference = None
puzzles = list(map(int, input().split()))
puzzles.sort()
for index in range(len(puzzles) - n):
	if min_difference == None or min_difference > puzzles[index + n] - puzzles[index]:
		min_difference = puzzles[index + n] - puzzles[index]
print(min_difference)


n = list(map(int, input().split()))[0]
a = sorted(map(int, input().split()))
print(min((a[i + n - 1] - a[i] for i in range(len(a) - n + 1))))


(n, m) = map(int, input().split())
piece = list(map(int, input().split()))
piece = sorted(piece)
result = []
for i in range(len(piece) - n + 1):
	small = piece[i]
	large = piece[i + n - 1]
	diff = large - small
	result.append(diff)
result = sorted(result)
print(result[0])


(n, m) = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
best = int(1e+18)
for i in range(0, m - n + 1):
	best = min(best, A[n + i - 1] - A[i])
print(best)


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


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
mini = arr[0]
maxi = arr[0]
for i in range(n):
	if arr[i] < mini:
		mini = arr[i]
	if arr[i] > maxi:
		maxi = arr[i]
diff = maxi - mini
i = 1
while i <= m - n:
	mini = arr[i]
	maxi = arr[i]
	for j in range(i + 1, i + n):
		if arr[j] < mini:
			mini = arr[j]
		if arr[j] > maxi:
			maxi = arr[j]
	if maxi - mini < diff:
		diff = maxi - mini
	i += 1
print(diff)


LM = lambda : map(int, input().split())
(s, r) = LM()
q = sorted(LM())
print(min((f - g for (g, f) in zip(q, q[s - 1:]))))


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


(m, n) = map(int, input().split())
a = [int(x) for x in input().split()]
a = sorted(a)
min = a[n - 1] - a[0]
if m == n:
	print(min)
else:
	for i in range(0, n - m + 1):
		ans = a[i + m - 1] - a[i]
		if ans < min:
			min = ans
	print(min)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
min1 = float('inf')
for i in range(n - 1, m):
	if a[i] - a[i - n + 1] < min1:
		min1 = a[i] - a[i - n + 1]
print(min1)


(students, puzzles) = map(int, input().split())
puzzle = sorted(list(map(int, input().split())))
m = float('inf')
for i in range(puzzles - students + 1):
	m = min(m, puzzle[i + students - 1] - puzzle[i])
print(m)


c = 10000
(n, m) = input().split()
n = int(n)
m = int(m)
a = list((int(x) for x in input().split()))
a.sort()
for i in range(len(a)):
	if i + n < len(a) + 1:
		c = min(c, abs(a[i] - a[i + n - 1]))
	if i + n == len(a):
		break
print(c)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
l.reverse()
mi = 100000000
for i in range(m - n + 1):
	if l[i] - l[i + n - 1] < mi:
		mi = l[i] - l[i + n - 1]
print(mi)


(d, f) = list(map(int, input().split()))
s = list(map(int, input().split()))
s.sort()
a = []
try:
	for i in range(f):
		o = s[i + (d - 1)] - s[i]
		a.append(o)
except:
	pass
print(min(a))


first = input()
(n, m) = (int(first.split(' ')[0]), int(first.split(' ')[1]))
sec = input()
arr = [int(num) for num in sec.split(' ')]
arr1 = sorted(arr)
ans = arr1[m - 1] - arr1[0]
for i in range(m - n + 1):
	ans = min(ans, arr1[i + n - 1] - arr1[i])
print(ans)


(n, m) = map(int, input().split())
ls = sorted([int(x) for x in input().split()])
ans = 1000000005
for i in range(m - n + 1):
	ans = min(ans, ls[i + n - 1] - ls[i])
print(ans)


I = [int(i) for i in input().split()]
(n, m) = (I[0], I[1])
Puz = sorted([int(i) for i in input().split()])
ans = Puz[-1]
for i in range(m - n + 1):
	if Puz[i + n - 1] - Puz[i] < ans:
		ans = Puz[i + n - 1] - Puz[i]
print(ans)


(n, m) = map(int, input().split())
f = [int(x) for x in input().split()]
f.sort()
s = []
if n == m:
	print(f[~0] - f[0])
else:
	for i in f[0:m - n + 1]:
		a = f[f.index(i) + n - 1] - i
		s.append(a)
	print(min(s))


(n, m) = [int(i) for i in input().split()]
list1 = [int(i) for i in input().split()]
list1.sort()
s = 10000
for i in range(m - n + 1):
	if list1[i + n - 1] - list1[i] < s:
		s = list1[i + n - 1] - list1[i]
print(s)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
best = 10000000000.0
for k in range(0, m - n + 1):
	best = min(best, a[k + n - 1] - a[k])
print(best)


(a, b) = map(int, input().split())
c = list(map(int, input().split()))
d = c.sort()
min = 1001
for i in range(b - a + 1):
	if c[i + a - 1] - c[i] < min:
		min = c[i + a - 1] - c[i]
print(min)


(n, m) = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
minn = 10000000
for i in range(0, m - n + 1):
	if abs(A[n + i - 1] - A[i]) < minn:
		minn = A[n + i - 1] - A[i]
print(minn)


(n, m) = map(int, input().split())
puzzles = sorted(map(int, input().split()))
best = 1000
for i in range(m - n + 1):
	best = min(best, puzzles[i + n - 1] - puzzles[i])
print(best)


(n, m) = map(int, input().split())
lst = list(map(int, input().split()))
lst.sort()
mi = float('inf')
for i in range(m - n + 1):
	mi = min(mi, lst[i + n - 1] - lst[i])
print(mi)


from collections import defaultdict

def main():
	(n, m) = map(int, input().split())
	f_list = list(sorted(list(map(int, input().split()))))
	ans = f_list[-1] - f_list[0]
	for i in range(len(f_list) - (n - 1)):
		ans = min(ans, f_list[i + n - 1] - f_list[i])
	print(ans)
main()


(n, m) = map(int, input().split())
s = list(map(int, input().split()))
for i in range(m):
	mini = i
	for j in range(i, m):
		if s[j] < s[mini]:
			mini = j
	(s[mini], s[i]) = (s[i], s[mini])
if n == m:
	print(s[n - 1] - s[0])
else:
	mini = 1001
	for i in range(m - n + 1):
		if s[i + n - 1] - s[i] < mini:
			mini = s[i + n - 1] - s[i]
	print(mini)


i = input
n = int(i().split()[0])
p = sorted(map(int, i().split()))
print(min((r - l for (l, r) in zip(p, p[n - 1:]))))


(n, m) = map(int, input().split())
f = sorted(list(map(int, input().split())))
best = 1001
for k in range(m - n + 1):
	best = min(best, f[k + n - 1] - f[k])
print(best)


import sys
from os import path
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
(n, m) = map(int, input().split())
l = sorted(list(map(int, input().split())))
print(min([l[i + n - 1] - l[i] for i in range(m - n + 1)]))


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort(reverse=True)
ans = 0
mm = 100000
for i in range(m - n + 1):
	ans = l[i] - l[i + n - 1]
	if ans < mm:
		mm = ans
if mm == 100000:
	print(0)
else:
	print(mm)


(n, m) = [int(x) for x in input().split()]
L = [int(a) for a in input().split()]
K = sorted(L)
if m != n:
	p = []
	for i in range(m - n + 1):
		s = K[i + n - 1] - K[i]
		p.append(s)
	print(min(p))
elif m == n:
	print(max(K) - min(K))


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


(n, m) = map(int, input().split())
(f, minimum) = (sorted(list(map(int, input().split()))), 10 ** 6)
for i in range(m - n + 1):
	minimum = min(minimum, f[i + n - 1] - f[i])
print(minimum)


(m, n) = map(int, input().split())
f = list(map(int, input().split()))
f.sort()
min_diff = 1000
for i in range(n - m + 1):
	diff = f[i + m - 1] - f[i]
	if diff < min_diff:
		min_diff = diff
print(min_diff)


(m, n) = input().split()
A = input()
B = []
m = int(m)
n = int(n)
Sum = 1001
p = 0
for i in A.split():
	B.append(int(i))
B.sort()
for j in range(0, n - m + 1):
	a = B[j + m - 1] - B[j]
	if a <= Sum:
		Sum = a
print(Sum)


(q, w) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
s = 10000
for i in range(0, w - q + 1):
	s = min(s, a[i + q - 1] - a[i])
print(s)


mini = 99999999
line1 = list(map(int, input().split()))
(n, m) = line1
line2 = list(map(int, input().split()))
arr = line2
arr.sort()
for i in range(m - n + 1):
	temp = arr[n + i - 1] - arr[i]
	if temp < mini:
		mini = temp
print(mini)


(n, m) = map(int, input().split())
nums = list(map(int, input().split()))
nums.sort()
minim = 10000000000
for i in range(m - n + 1):
	minim = min(nums[i + n - 1] - nums[i], minim)
print(minim)


(n, m) = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
if m == n:
	print(abs(p[0] - p[n - 1]))
else:
	diff = p[m - 1] - p[0]
	for i in range(m - n + 1):
		puz = []
		for j in range(i, i + n):
			puz.append(p[j])
		newdiff = puz[n - 1] - puz[0]
		if newdiff <= diff:
			diff = newdiff
			continue
		else:
			continue
	print(diff)


(c, a) = map(int, input().split())
d = list(map(int, input().split()))
d.sort()
r = [d[i + c - 1] - d[i] for i in range(a - c + 1)]
print(min(r))


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


(n, m) = map(int, input().split())
x = list(map(int, input().split()))
x = sorted(x)
ans = float('inf')
for i in range(0, m - (n - 1)):
	if x[i + (n - 1)] - x[i] < ans:
		ans = x[i + (n - 1)] - x[i]
print(ans)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort(reverse=True)
o = []
if m == n:
	print(max(l) - min(l))
else:
	for i in range(m - n + 1):
		o.append(l[i] - l[i + n - 1])
	print(min(o))


import sys

def ans(arr, n):
	arr.sort()
	l = 0
	r = n - 1
	minimum = sys.maxsize
	while r < len(arr):
		minimum = min(minimum, arr[r] - arr[l])
		l += 1
		r += 1
	return minimum
	pass
(n, m) = list(map(int, input().strip().split(' ')))
arr = list(map(int, input().strip().split(' ')))
print(ans(arr, n))


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
z = []
for i in range(0, m - n + 1):
	zz = []
	for j in range(i, i + n):
		zz.append(a[j])
	z.append(max(zz) - min(zz))
print(min(z))


test_input = input()
test_input = test_input.split()
num_students = int(test_input[0])
num_puzzles = int(test_input[1]) + 1
puz_pieces = input()
puz_pieces = puz_pieces.split()
puz_pieces = [int(x) for x in puz_pieces]
puz_pieces.sort()
puz_pieces.append(0)
test_list = []
difference = puz_pieces[-2] - puz_pieces[0]
for x in range(num_students, len(puz_pieces)):
	test_list = puz_pieces[x - num_students:x]
	if test_list[-1] - test_list[0] < difference:
		difference = test_list[-1] - test_list[0]
print(difference)


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

def main():
	(n, m) = read_list()
	puzzles = read_list()
	puzzles.sort()
	min_difference = puzzles[-1] - puzzles[0]
	for i in range(m):
		last_puzzle_idx = i + n - 1
		if last_puzzle_idx > m - 1:
			break
		min_complexity = min(puzzles[i:last_puzzle_idx + 1])
		max_complexity = max(puzzles[i:last_puzzle_idx + 1])
		min_difference = min(min_difference, max_complexity - min_complexity)
	print(min_difference)
main()


(n, m) = list(map(int, input().split()))
P = list(map(int, input().split()))
P.sort()
S = [-1] * len(P)
S[n - 1] = ans = P[n - 1] - P[0]
for i in range(n, len(P)):
	S[i] = P[i] - P[i - (n - 1)]
	if S[i] < ans:
		ans = S[i]
print(ans)


kalanbaba = 1
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
(n, m) = I()
l = I()
l.sort()
mm = 10 ** 10
for i in range(m - n + 1):
	if l[i + n - 1] - l[i] < mm:
		mm = l[i + n - 1] - l[i]
print(mm)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
k = n
mn = float('inf')
for i in range(0, len(a) - k + 1):
	sub = a[i:i + k]
	mn = min(mn, sub[-1] - sub[0])
print(mn)


(n, m) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
A.sort()
ans = 1 << 30
for i in range(m - n + 1):
	ans = min(ans, A[i + n - 1] - A[i])
print(ans)


nandm = input()
strpuzzles = input()
puzzles = list(map(int, strpuzzles.split(' ')))
n = int(nandm.split(' ')[0])
m = int(nandm.split(' ')[1])
devs = []
puzzles.sort()
for puzzle in range(len(puzzles)):
	if puzzle + n <= len(puzzles):
		chosen = puzzles[puzzle:puzzle + n]
		devs.append(max(chosen) - min(chosen))
	else:
		break
print(min(devs))


(a, b) = map(int, input().split())
aa = [int(i) for i in input().split()]
aa = sorted(aa)
vv = []
for i in range(b - a + 1):
	v = aa[i:i + a]
	vv.append(max(v) - min(v))
print(min(vv))


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
dif = 10000000000000000
l.sort()
for i in range(m - n + 1):
	nl = l[i:i + n]
	nl.sort()
	if dif > nl[n - 1] - nl[0]:
		dif = nl[n - 1] - nl[0]
print(dif)


def get():
	return [int(x) for x in input().split()]
(n, m) = get()
x = get()
x.sort()
mn = 1000
for i in range(n, m + 1):
	mn = min(mn, x[i - 1] - x[i - n])
print(mn)


(n, m) = [int(i) for i in input().split()]
li = [int(i) for i in input().split()]
(su2, k, su) = (10000, 0, 0)
li.sort(reverse=True)
for i in range(m - n + 1):
	su = li[i] - li[i + n - 1]
	if su < su2:
		k = i
		su2 = su
	su = 0
print(li[k] - li[k + n - 1])


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


(n, m) = input().split()
(n, m) = (int(n), int(m))
a = input().split()
list(a)
a = [int(x) for x in a]
a.sort()
mn = 9999999999
for i in range(n - 1, m):
	if int(a[i]) - int(a[i - n + 1]) < mn:
		mn = int(a[i]) - int(a[i - n + 1])
print(mn)


dist = 1001
line1 = input()
(n, m) = (int(i) for i in line1.split())
line2 = input()
pazl = [int(n) for n in line2.split()]
pazl.sort()
for i in range(n - 1, m):
	if pazl[i] - pazl[i - n + 1] < dist:
		dist = pazl[i] - pazl[i - n + 1]
print(dist)


a = input().split()
n = int(a[0])
m = a[1]
indmin = 0
b = [int(x) for x in input().split()]
for i in range(0, len(b)):
	indmin = i
	for j in range(i + 1, len(b)):
		if b[j] < b[indmin]:
			indmin = j
	(b[i], b[indmin]) = (b[indmin], b[i])
minraz = 10000000
for i in range(0, len(b) - n + 1):
	raz = b[i + n - 1] - b[i]
	if raz < minraz:
		minraz = raz
print(minraz)


data = [int(x) for x in input().split()]
pieces = sorted([int(x) for x in input().split()])
min_ = max(pieces)
for n in range(len(pieces) - data[0] + 1):
	if abs(max(pieces[n:n + data[0]]) - min(pieces[n:n + data[0]])) < min_:
		min_ = abs(max(pieces[n:n + data[0]]) - min(pieces[n:n + data[0]]))
print(min_)


(n, p) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
(p1, p2, ans) = (0, n - 1, 10 ** 6)
while p2 < p:
	ans = min(ans, arr[p2] - arr[p1])
	p1 += 1
	p2 += 1
print(ans)


(n, k) = [int(x) for x in input().split(' ')]
arr = sorted([int(x) for x in input().split(' ')])
ans = max(arr)
for i in range(k - n + 1):
	ans = min(ans, abs(max(arr[i:i + n]) - min(arr[i:i + n])))
print(ans)


n = list(map(int, input().split()))
q = list(map(int, input().split()))
q.sort()
i = 0
j = n[0] - 1
m = q[j] - q[i]
while j < len(q):
	if q[j] - q[i] < m:
		m = q[j] - q[i]
	i += 1
	j += 1
print(m)


(n, m) = [int(x) for x in input().split()]
tiling = [int(x) for x in input().split()]
tiling.sort()
c1 = int(tiling[-1]) - int(tiling[0])
for i in range(0, m - n + 1):
	c = int(tiling[i + n - 1]) - int(tiling[i])
	c1 = min(c, c1)
print(c1)


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
f = sorted(f)
diff = f[m - 1] - f[0]
i = 0
while i <= m - n:
	if f[i + n - 1] - f[i] < diff:
		diff = f[i + n - 1] - f[i]
	i += 1
print(diff)


from collections import Counter
(n, m) = map(int, input().split())
l = [int(i) for i in input().split()]
c = Counter(l)
v = list(c.values())
if n in v:
	print('0')
else:
	l = sorted(l)
	mini = 9999999999999
	for g in range(0, m):
		try:
			if l[g + n - 1] - l[g] < mini:
				mini = l[g + n - 1] - l[g]
		except IndexError:
			break
	print(mini)


(n, m) = map(int, input().strip().split())
l = sorted(list(map(int, input().strip().split())))
result = 99999
for i in range(m - n + 1):
	result = min(result, l[i + n - 1] - l[i])
print(result)


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


(n, m) = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
out = 1001
for i in range(len(A) - n + 1):
	B = A[i:i + n]
	if max(B) - min(B) < out:
		out = max(B) - min(B)
print(out)


s = input()
s = s.split()
n = int(s[0])
m = int(s[1])
s = input()
s = s.split()
for i in range(len(s)):
	s[i] = int(s[i])
s.sort()
k = n - 1
best = 1000000000000
start = 0
while 1:
	best = min(best, s[k] - s[start])
	start += 1
	k += 1
	if k == len(s):
		break
print(best)


i = input('')
i = list(i.split())
n = int(i[0])
m = int(i[1])
f = input('')
f = list(f.split())
for i in range(len(f)):
	f[i] = int(f[i])
f.sort(reverse=True)
b = []
for i in range(len(f) - n + 1):
	k = f[i:i + n]
	maxk = max(k)
	mink = min(k)
	d = maxk - mink
	b.append(d)
print(min(b))


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


(n, m) = map(int, input().split())
s = [int(elem) for elem in input().split()]
s.sort()
minn = 10 ** 9 + 1
for i in range(m - n + 1):
	if s[i + n - 1] - s[i] < minn:
		minn = s[i + n - 1] - s[i]
print(minn)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
mx = 9999999999999
for i in range(k - n + 1):
	a = arr[i:i + n]
	mx = min(mx, max(a) - min(a))
print(mx)


(n, m) = map(int, input().split())
nums = map(int, input().split())
nums = sorted(nums)
min_diff = 9999999999999
for i in range(n - 1, len(nums)):
	diff = nums[i] - nums[i - n + 1]
	if min_diff >= diff:
		min_diff = diff
print(min_diff if min_diff != 9999999999999 else 0)


(N, M) = map(int, input().split())
F = list(map(int, input().split()))
F.sort()
ans = int(1e+18)
for i in range(M - (N - 1)):
	ans = min(ans, F[i + N - 1] - F[i])
print(ans)


(n, m) = map(int, input().split())
puzzles = list(map(int, input().split()))
puzzles.sort(reverse=True)
minDiff = 10 ** 20
for i in range(0, m - n + 1):
	minDiff = min(minDiff, puzzles[i] - puzzles[i + n - 1])
print(minDiff)


(a, b) = map(int, input().split())
c = sorted(list(map(int, input().split())))
d = c[a - 1] - c[0]
for i in range(b - a + 1):
	d = min(d, c[i + a - 1] - c[i])
print(d)


(n, m) = map(int, input().split())
a = sorted(list(map(int, input().split())))
start = 0
end = n - 1
_min = a[end] - a[start]
while end + 1 < m:
	start += 1
	end += 1
	_min = min(_min, a[end] - a[start])
print(_min)


(n, m) = map(int, input().split())
puzzles = list(map(int, input().split()))
puzzles = sorted(puzzles)
ans = 1000
for i in range(n, m + 1):
	ans = min(ans, puzzles[i - 1] - puzzles[i - n])
print(ans)


s = input().split(' ')
n = int(s[0])
m = int(s[1])
s = input().split(' ')
s = [int(x) for x in s]
s.sort(reverse=True)
l = []
for i in range(len(s) - n + 1):
	l = l + [abs(s[i] - s[i + n - 1])]
print(min(l))


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


n = [int(x) for x in input().split()]
f = [int(y) for y in input().split()]
f.sort()
for i in range(n[1] - n[0] + 1):
	temp = f[i + n[0] - 1] - f[i]
	if i == 0:
		mini = temp
	else:
		mini = min(mini, temp)
print(mini)


(n, m) = map(int, input().split(' '))
lis = list(map(int, input().split(' ')))
lis.sort()
ans = 999999999999
for i in range(0, m - n + 1):
	su = lis[i + n - 1] - lis[i]
	if ans > su:
		ans = su
print(ans)


(n, m) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a = sorted(a)
mi = a[n - 1] - a[0]
for i in range(0, m - n + 1):
	te = a[i + n - 1] - a[i]
	mi = min(mi, te)
print(mi)


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


(n, m) = map(int, input().split())
f = [int(x) for x in input().split()]
t = []
s = []
k = []
p = 0
for i in range(m):
	for u in range(m):
		if u != i:
			t.append(f[i] - f[u])
			b = tuple(t)
	t.append(0)
	for l in b:
		if l > 0:
			t.remove(l)
		else:
			la = -l
			k.append(la)
	k.sort()
	s.append(k)
	t = []
	k = []
	b = ()
w = tuple(s)
for i in w:
	if len(i) < n - 1:
		s.remove(i)
o = []
for i in s:
	p = i[n - 2]
	o.append(p)
o.sort()
j = o[0]
print(j)


a = input()
a = [int(i) for i in a.split()]
b = input()
b = [int(i) for i in b.split()]
b.sort()
if a[0] == a[1]:
	min_dif = b[-1] - b[0]
elif a[0] == 2:
	equal = False
	for i in range(len(b) - 1):
		if b[i] == b[i + 1]:
			equal = True
			break
	if equal:
		min_dif = 0
	else:
		min_dif = b[a[0] - 1] - b[0]
else:
	min_dif = 1000
	for i in range(a[1] - (a[0] - 1)):
		dif = b[i + a[0] - 1] - b[i]
		if dif < min_dif:
			min_dif = dif
print(min_dif)


(n, m) = map(int, input().split())
F = list(map(int, input().split()))
F.sort()
x = 10000000000000000000
for i in range(m - n + 1):
	p = F[i:i + n]
	mm = p[-1] - p[0]
	if mm < x:
		x = mm
print(x)


def __starting_point():
	inp = input()
	arr = inp.split(' ')
	n = int(arr[0])
	m = int(arr[1])
	inp = input()
	arr = inp.split(' ')
	L = []
	for s in arr:
		L.append(int(s))
	L.sort()
	diff = L[n - 1] - L[0]
	for i in range(m - n + 1):
		diff = min(diff, L[i + n - 1] - L[i])
	print(diff)
__starting_point()


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


def manana(puzzlez, almn):
	puzzlez.sort()
	a = abs(puzzlez[0] - puzzlez[almn - 1])
	for i in range(len(puzzlez) - almn + 1):
		if abs(puzzlez[i] - puzzlez[i + almn - 1]) < a:
			a = abs(puzzlez[i] - puzzlez[i + almn - 1])
	return a
(n, m) = map(int, input().split())
puzzlez = list(map(int, input().split()))
print(manana(puzzlez, n))


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


from sys import stdin, stdout
import sys
(n, m) = map(int, stdin.readline().rstrip().split())
f = list(map(int, stdin.readline().rstrip().split()))
f.sort()
r = sys.maxsize
i = 0
while i + n <= m:
	r = min(r, f[i + n - 1] - f[i])
	i += 1
print(r)


def main():
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	list_str = list(input().split())
	list_num = []
	out = []
	for q in list_str:
		d = int(q)
		list_num += [d]
	list_num.sort()
	delta = m - n + 1
	for k in range(delta):
		l = k + n - 1
		out += [list_num[l] - list_num[k]]
	out.sort()
	print(out[0])
main()


(n, m) = map(int, input().split(' '))
k = list(map(int, input().split()))
k.sort()
b = 1000
for i in range(m - n + 1):
	j = k[i + n - 1] - k[i]
	if j < b:
		b = j
print(b)


(n, m) = map(int, input().split())
array = [int(i) for i in input().split()]
array = sorted(array)
ans = float('inf')
for i in range(m - n + 1):
	minSum = array[i + n - 1] - array[i]
	if minSum <= ans:
		ans = minSum
print(ans)


(num1, num2) = map(int, input().split(' '))
res = sorted(map(int, input().split(' ')))
print(min((j - i for (i, j) in zip(res, res[num1 - 1:]))))


(n, m) = [int(i) for i in input().split()]
A = [int(a) for a in input().split()]
diff = []
A.sort()
x = 0
y = n - 1
while x < m and y < m:
	diff.append(A[y] - A[x])
	x += 1
	y += 1
print(min(diff))


(n, s) = map(int, input().split())
p = sorted(list(map(int, input().split())))
print(min((j - i for (i, j) in zip(p, p[n - 1:]))))


(n, m) = map(int, input().split())
A = sorted(list(map(int, input().split())))
count = 100000000000
for i in range(m - 1, -1, -1):
	if i - n + 1 < 0:
		break
	else:
		count = min(count, A[i] - A[i - n + 1])
print(count)


(n, m) = input().split(' ')
n = int(n)
m = int(m)
a = input().split(' ')
x = [int(i) for i in a]
x = sorted(x)
b = list()
for j in range(0, m - n + 1):
	cnt = 0
	for i in range(0, n - 1):
		cnt += x[j + i + 1] - x[j + i]
	b.append(cnt)
print(min(b))


(a, b) = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
c.sort()
menor = 1000
i = a - 1
while i < b:
	if c[i] - c[i - a + 1] < menor:
		menor = c[i] - c[i - a + 1]
	i += 1
print(menor)


def read_numbers():
	return list(map(int, input().split()))
(n, m) = read_numbers()
numbers = read_numbers()
numbers.sort()
best = numbers[-1] - numbers[0]
for i in range(len(numbers) - n + 1):
	if numbers[i + n - 1] - numbers[i] < best:
		best = numbers[i + n - 1] - numbers[i]
print(best)


(n, m) = input().split()
(n, m) = (int(n), int(m))
p = list(map(int, input().split()))
p = sorted(p)
mm = 1000
for i in range(m):
	if i + n - 1 < m and abs(p[i] - p[i + n - 1]) < mm:
		mm = abs(p[i] - p[i + n - 1])
print(mm)


(a, b) = map(int, input().split())
c = input().split()
d = []
for i in c:
	d.append(int(i))
d.sort()
m = d[b - 1]
for j in range(b - a + 1):
	n = d[j + a - 1] - d[j]
	m = min(m, n)
print(m)


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


from math import inf
(n, k) = map(int, input().split())
l = input()
l = [int(i) for i in l.split()]
l = sorted(l)
ans = inf
for i in range(0, k - n + 1):
	ans = min(ans, l[i + n - 1] - l[i])
if ans == inf:
	print(0)
else:
	print(ans)


(n, m) = [int(x) for x in input().split()]
l1 = input()
l = l1.split()
pz = []
for i in l:
	pz.append(int(i))
pz.sort()
pz.sort()
if m == n:
	mn = int(pz[m - 1] - pz[0])
else:
	mn = 100000
	for i in range(m - n + 1):
		mn = min(int(int(pz[i + n - 1]) - int(pz[i])), mn)
print(mn)


n = input()
n = n.split()
p = int(n[0])
q = int(n[1])
m = input()
m = m.split()
for i in range(q):
	m[i] = int(m[i])
m.sort()
d = m[p - 1] - m[0]
for i in range(p, q):
	e = m[i] - m[i - (p - 1)]
	if e < d:
		d = e
print(d)


def main():
	from sys import stdout
	(N, M) = map(int, input().split())
	pieces = sorted(map(int, input().split()))
	ans = min((pieces[i] - pieces[i - N + 1] for i in range(N - 1, M)))
	stdout.write(str(ans))
main()


(n, m) = map(int, input().split())
l = sorted(map(int, input().split()))
x = max(l)
for i in range(m - n + 1):
	x = min(x, l[i + n - 1] - l[i])
print(x)


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
f.sort()
l = 0
min = 10000
n = n - 1
while l + n < len(f):
	r = l + n
	diff = f[r] - f[l]
	if diff < min:
		min = f[r] - f[l]
	l = l + 1
print(min)


(n, m) = map(int, input().split())
k = input().split()
a = [int(i) for i in k]
a.sort()
a.reverse()
mi = 1001
for i in range(len(a) - n + 1):
	mi = min(mi, a[i] - a[i + n - 1])
print(mi)


(n, m) = map(int, input().split())
pz = list(map(int, input().split()[:m]))
pz.sort()
diffs = []
for i in range(0, m - n + 1):
	diff = pz[n + i - 1] - pz[i]
	diffs.append(diff)
diffs.sort()
print(diffs[0])


(n, m) = list(map(int, input().split()))
f = list(map(int, input().split()))
f = sorted(f)
if n == m:
	print(f[-1] - f[0])
else:
	ind1 = 0
	ind2 = ind1 + n - 1
	sc = [f[ind2] - f[ind1]]
	while ind2 + 1 < m:
		ind1 += 1
		ind2 = ind1 + n - 1
		sc.append(f[ind2] - f[ind1])
	print(min(sc))


(m, t) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
a.sort()
b = []
n = m
x = 0
while n - 1 < len(a):
	b.append(a[n - 1] - a[x])
	n += 1
	x += 1
print(min(b))


st = input().split()
n = int(st[0])
m = int(st[1])
a = []
st = map(int, input().split())
for i in st:
	a.append(i)
a.sort()
mindis = 10000
for i in range(n - 1, m):
	mindis = min(mindis, a[i] - a[i - n + 1])
print(mindis)


from collections import deque, Counter, OrderedDict
from heapq import nsmallest, nlargest
from math import ceil, floor, log, log2, sqrt

def binNumber(n, size=1):
	return bin(n)[2:].zfill(size)

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

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

def ini():
	return int(input())

def isp():
	return map(int, input().split())

def sti():
	return str(input())
(n, m) = isp()
a = iar()
a.sort()
i = 0
c = 10000000
while i < m - n + 1:
	c = min(c, a[i + n - 1] - a[i])
	i += 1
print(c)


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


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


(n, m) = map(int, input().split())
p = input().split()
lst = []
for i in range(int(m)):
	p[i] = int(p[i])
p.sort()
for i in range(m):
	if i + (n - 1) > m - 1:
		lst.append(p[m - 1] - p[0])
	else:
		lst.append(p[n - 1 + i] - p[i])
print(min(lst))


(n, m) = input().split()
n = int(n) - 1
m = int(m)
f = [int(x) for x in input().split()]
f.sort()
min = 100000
i = 0
while i + n < len(f):
	if f[i + n] - f[i] < min:
		min = f[i + n] - f[i]
	i += 1
print(str(min))


import sys
li = [int(i) for i in input().split()]
n = li[0]
m = li[1]
li1 = [int(i) for i in input().split()]
li1.sort()
mi = sys.maxsize
i = 0
while i + n - 1 < m:
	mi = min(mi, abs(li1[i] - li1[i + n - 1]))
	i += 1
print(mi)


(N, M) = [int(n) for n in input().split()]
L = [int(i) for i in input().split()]
L.sort()
ans = L[N - 1] - L[0]
for i in range(M - N + 1):
	c = L[N - 1 + i] - L[i]
	if c < ans:
		ans = c
print(ans)


(n, m) = map(int, input().split())
puzzle = list(map(int, input().split()))
if n == len(puzzle):
	print(max(puzzle) - min(puzzle))
else:
	puzzle.sort()
	i = 0
	ans = max(puzzle)
	while i + n < len(puzzle) + 1:
		temp = puzzle[i:i + n]
		diff = max(temp) - min(temp)
		ans = min(ans, diff)
		i = i + 1
	print(ans)


(n, m) = list(map(int, input().split()))
sizes = list(map(int, input().split()))

def puzzles(sizes, n, m):
	if n == m:
		return max(sizes) - min(sizes)
	sizes.sort()
	curr_min = float('inf')
	for i in range(m - n + 1):
		curr_min = min(curr_min, sizes[i + n - 1] - sizes[i])
	return curr_min
print(puzzles(sizes, n, m))


(n, m) = map(int, input().strip().split())
v = list(map(int, input().strip().split()))
v.sort()
mini = v[n - 1] - v[0]
for i in range(1, m - n + 1):
	aux = v[i + n - 1] - v[i]
	if aux < mini:
		mini = aux
print(mini)


(a, b) = input().split()
a = int(a)
b = int(b)
y = input().split()
L = []
for i in y:
	L.append(int(i))
least = 1000000
L.sort()
for i in range(0, b - a + 1):
	for j in range(i + a - 1, b):
		count = L[j] - L[i]
		if count < least:
			least = count
print(least)


nm = input().split(' ')
stores = input().split(' ')
for i in range(len(stores)):
	stores[i] = int(stores[i])
stores.sort()
i = int(nm[0]) - 1
initial = 0
globalSum = 20000
while i < len(stores):
	if stores[i] - stores[initial] < globalSum:
		globalSum = stores[i] - stores[initial]
	i += 1
	initial += 1
print(globalSum)


(n, m) = map(int, input().split())
t = list(map(int, input().split()))
t.sort()
k = 2000
for x in range(m - n + 1):
	z = max(t[x:x + n]) - min(t[x:x + n])
	if k > z:
		k = z
print(k)


(n, m) = map(int, input().split())
ar = sorted(list(map(int, input().split())))
ans = 1001
for i in range(m - n + 1):
	ans = min(ans, ar[i + n - 1] - ar[i])
print(ans)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
l1 = []
a = 0
b = n - 1
while b < m:
	l1.append(l[b] - l[a])
	b += 1
	a += 1
print(min(l1))


[n, m] = [int(e) for e in input().split(' ')]
groups = [int(a) for a in input().split(' ')]
sort = []
while len(groups) > 0:
	count = 0
	min = groups[0]
	while count < len(groups):
		i = groups[count]
		if i < min:
			min = i
		count += 1
	groups.remove(min)
	sort = sort + [min]
k = 0
min = sort[n - 1] - sort[0]
while k <= len(sort) - n:
	dif = sort[k + n - 1] - sort[k]
	k += 1
	if dif < min:
		min = dif
print(min)


students = int(input().split(' ')[0])
puzzles = list(map(int, input().split(' ')))
minDif = 1000
puzzles.sort()
for i in range(len(puzzles) - students + 1):
	slicedArray = puzzles[i:i + students]
	dif = max(slicedArray) - min(slicedArray)
	if dif < minDif:
		minDif = dif
print(minDif)


(n, m) = map(int, input().split())
l = [int(x) for x in input().split()]
l.sort()
for i in range(m - n + 1):
	temp = l[i + (n - 1)] - l[i]
	if i == 0:
		diff = temp
	if temp < diff:
		diff = temp
print(diff)


(n, m) = [int(i) for i in input().split()]
f = [int(i) for i in input().split()]
f.sort()
S = f[m - 1] - f[0]
for i in range(m - n + 1):
	s = f[i + n - 1] - f[i]
	if s < S:
		S = s
print(S)


spl = input().split()
n_gifts = int(spl[0])
n_total = int(spl[1])
res = 99999999999
nums = sorted(list(map(int, input().split())))
for i in range(n_total - n_gifts + 1):
	res = min(res, nums[i + n_gifts - 1] - nums[i])
print(res)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
slist = sorted(l)
sub_results = []
for i in range(0, m - n + 1):
	sub = slist[i + n - 1] - slist[i]
	sub_results.append(sub)
print(min(sub_results))


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
i = 0
l1 = []
k = 0
while i + n - 1 <= len(l) - 1:
	k = l[i] - l[i + n - 1]
	if k < 0:
		k = k * -1
	l1.append(k)
	i += 1
print(min(l1))


(n, m) = map(int, input().split())
a_list = [int(x) for x in input().split()]
a_list = sorted(a_list)
minn = 999999
for i in range(0, m - n + 1):
	if a_list[i + n - 1] - a_list[i] < minn:
		minn = a_list[i + n - 1] - a_list[i]
print(str(minn))


(n, m) = input().split()
n = int(n)
m = int(m)
f = list(map(int, input().split()))
f.sort()
i = 1
a = f[n - 1] - f[0]
while i + n - 1 < m:
	t = f[i + n - 1] - f[i]
	if a > t:
		a = t
	i += 1
print(a)


Inputs = list(map(int, input().split()))
ClassSize = Inputs[0]
PuzzlesCount = Inputs[1]
ActualPuzzles = list(map(int, input().split()))
ActualPuzzles.sort()
Diff = ActualPuzzles[-1] - ActualPuzzles[0]
if PuzzlesCount != ClassSize:
	for i in range(PuzzlesCount - ClassSize + 1):
		Temp = ActualPuzzles[i + ClassSize - 1] - ActualPuzzles[i]
		if Temp < Diff:
			Diff = Temp
		if Temp == 0:
			break
print(Diff)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
mn = 100000000000
for i in range(0, len(a)):
	if i + n - 1 < len(a):
		mn = min(mn, a[i + n - 1] - a[i])
print(mn)


jojo = [int(x) for x in input().split()]
m = jojo[1]
n = jojo[0]
p = [int(x) for x in input().split()]
p.sort()
ss = []
for i in range(m - n + 1):
	dio = p[i + n - 1] - p[i]
	ss.append(dio)
print(min(ss))


import sys
import math

def inp():
	return sys.stdin.readline().strip()

def iinp():
	return int(input())

def rinp():
	return map(int, sys.stdin.readline().strip().split())

def gl():
	return list(map(int, sys.stdin.readline().strip().split()))
(n, m) = rinp()
f = gl()
f.sort()
ans = 100000
for i in range(m - n + 1):
	ans = min(ans, f[i + n - 1] - f[i])
print(ans)


k = list(map(int, input().split()))
n = list(map(int, input().split()))
n.sort()
l = []
a = 0
for i in range(k[1] - k[0] + 1):
	l.append(n[i:i + k[0]])
for i in n:
	if n.count(i) == k[0]:
		a = 1
		print(0)
		break
if a == 0:
	g = []
	for i in l:
		g.append(i[k[0] - 1] - i[0])
	h = min(g)
	print(h)


(n, m) = map(int, input().split())
f = sorted(map(int, input().split()))
_min = 10000
(a, b) = (0, n - 1)
while b < m:
	if f[b] - f[a] < _min:
		_min = f[b] - f[a]
	a += 1
	b += 1
print(_min)


(m, n) = map(int, input().split())
l = sorted(map(int, input().split()), reverse=True)
low = l[0] - l[m - 1]
for i in range(1, n - m + 1):
	if l[i] - l[i + m - 1] < low:
		low = l[i] - l[i + m - 1]
print(low)


(n, m) = [int(i) for i in input().split()]
puzzles = [int(i) for i in input().split()]
puzzles = sorted(puzzles)
ans = 10000
for i in range(m - n + 1):
	if puzzles[n + i - 1] - puzzles[i] < ans:
		ans = puzzles[n + i - 1] - puzzles[i]
print(ans)


def solve():
	raw = input().split(' ')
	(n, m) = (int(raw[0]), int(raw[1]))
	raw = input().split(' ')
	data = sorted([int(i) for i in raw])
	ret = 1000000
	for i in range(m - n + 1):
		s = data[i:i + n]
		(ma, mi) = (max(s), min(s))
		if ma - mi < ret:
			ret = ma - mi
	print(ret)
solve()


from sys import stdin
a = [int(x) for x in stdin.readline().rstrip().split()]
b = [int(x) for x in stdin.readline().rstrip().split()]
cSize = a[0]
puzz = sorted(b)
print(min([puzz[i + cSize - 1] - puzz[i] for i in range(0, len(puzz) - cSize + 1)]))


from sys import stdin

def solve(tc):
	(n, m) = map(int, stdin.readline().split())
	fm = list(map(int, stdin.readline().split()))
	fm.sort()
	best = fm[-1] - fm[0]
	for i in range(n - 1, m):
		best = min(best, fm[i] - fm[i - n + 1])
	print(best)
	pass
LOCAL_TEST = not __debug__
if LOCAL_TEST:
	infile = __file__.split('.')[0] + '-test.in'
	stdin = open(infile, 'r')
tcs = int(stdin.readline()) if LOCAL_TEST else 1
tc = 1
while tc <= tcs:
	solve(tc)
	tc += 1


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


(n, m) = map(int, input().split())
lis = list(map(int, input().split()))
lis.sort()
s = 0
e = n - 1
ans = lis[e] - lis[s]
while e != m - 1:
	s += 1
	e += 1
	ans = min(ans, lis[e] - lis[s])
print(ans)


(a, b) = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))
arr = sorted(arr)
ans = []
finans = 2142424
for j in range(b - a + 1):
	ans.clear()
	for i in range(a):
		ans.append(arr[i + j])
	finans = min((finans, max(ans) - min(ans)))
if b == a:
	for i in range(a):
		ans.append(arr[i])
	finans = max(ans) - min(ans)
print(finans)


(n, m) = map(int, input().split())
piece = [int(x) for x in input().split()]
piece.sort()
minimal = []
for i in range(m):
	if n + i - 1 >= m:
		break
	minimal = minimal + [piece[n + i - 1] - piece[i]]
print(min(minimal))


(n, m) = map(int, input().split())
p = input().split()
list1 = []
for i in range(m):
	list1.append(int(p[i]))
list1 = sorted(list1)
if n == m:
	print(list1[-1] - list1[0])
else:
	list2 = []
	for j in range(m - n + 1):
		d = list1[j + n - 1] - list1[j]
		list2.append(d)
	list2 = sorted(list2)
	print(list2[0])


(n, m) = map(int, input().split())
a = [int(s) for s in input().split()]
a = sorted(a)
mindif = 100000
for i in range(0, m - n + 1):
	dif = a[i + n - 1] - a[i]
	mindif = min(dif, mindif)
print(mindif)


(m, n) = (int(i) for i in input().split())
f = [int(s) for s in input().split()]
f.sort()
mn = f[m - 1] - f[0]
for i in range(n - m + 1):
	x = f[m - 1 + i] - f[i]
	if x < mn:
		mn = x
print(mn)


(n, m) = map(int, input().split())
a = list((int(num) for num in input().split()))
a.sort()
num = []
for i in range(m - n + 1):
	li = a[i:n + i]
	con = max(li) - min(li)
	num.append(con)
print(min(num))


class Puzzle:
	n = None
	m = None
	data = None

	def read(self):
		(self.n, self.m) = input().split(' ')
		self.n = int(self.n)
		self.m = int(self.m)
		self.data = list(map(int, input().split(' ')))
		self.data.sort()

	def calculate(self):
		result = self.data[self.n - 1] - self.data[0]
		for i in range(self.n, self.m):
			result = min(result, self.data[i] - self.data[i - self.n + 1])
		return result

def main():
	puzzles = Puzzle()
	puzzles.read()
	print(puzzles.calculate())
main()


(n, m) = map(int, input().strip().split())
J = list(map(int, input().strip().split()))
J.sort()
prev = 100000000
for i in range(m - n + 1):
	t = J[i + n - 1] - J[i]
	if t < prev:
		prev = t
print(prev)


(n, m) = [int(e) for e in input().split()]
v = sorted([int(e) for e in input().split()])
diff = [v[i] - v[i - n + 1] for i in range(n - 1, m)]
print(min(diff))


(stu, puz) = map(int, input().split())
pieces = [x for x in map(int, input().split())]
pieces = sorted(pieces)
best = 999999999999
for i in range(puz - stu + 1):
	best = min(best, pieces[i + stu - 1] - pieces[i])
print(best)


(n, m) = map(int, input().split())
num_list = sorted(list(map(int, input().split())))
best = 99999999
for i in range(0, m - n + 1):
	best = min(best, num_list[i + n - 1] - num_list[i])
if best == 99999999:
	print(0)
else:
	print(best)


def input_int(sep=' '):
	rst = [int(n) for n in input().split(sep) if n]
	return rst
(n, m) = input_int()
fs = input_int()
fs = sorted(fs)
diffs = [fs[i + n - 1] - fs[i] for i in range(m - n + 1)]
print(min(diffs))


(x, y) = map(int, input().split())
s = list(map(int, input().split()))
s.sort()
m = s[x - 1] - s[0]
for i in range(y - x + 1):
	a = s[i:i + x]
	z = a[-1] - a[0]
	if z < m:
		m = z
print(m)


(a, b) = [int(i) for i in input().split()]
s = [int(i) for i in input().split()]
s.sort()
res = s[-1]
for i in range(b - a + 1):
	difference = s[i + a - 1] - s[i]
	if difference < res:
		res = difference
print(res)


(a, b) = map(int, input().split())
k = list(map(int, input().split()))
k.sort()
diff = 9999999
for i in range(b + 1 - a):
	if k[a - 1 + i] - k[i] < diff:
		diff = k[a - 1 + i] - k[i]
print(diff)


values = input().split()
(n, m) = (int(values[0]), int(values[1]))
pieces = list(map(lambda x: int(x), input().split()))
pieces.sort()
result = pieces[-1]
if n == m:
	result = pieces[-1] - pieces[0]
for i in range(m - n + 1):
	difference = pieces[i + n - 1] - pieces[i]
	if difference < result:
		result = difference
		if result == 0:
			break
print(result)


import sys
(n, m) = map(int, input().strip().split(' '))
arr = list(map(int, input().strip().split(' ')))
arr.sort()
a = sys.maxsize
min_diff = a
for i in range(n - 1, m):
	min_diff = min(min_diff, arr[i] - arr[i - (n - 1)])
print(min_diff)


(n, m) = map(int, input().split(' '))
tiles_no = list(map(int, input().split(' ')))
tiles_no.sort()
min_diff = list()
for i in range(m - n + 1):
	sub = tiles_no[n + i - 1] - tiles_no[i]
	min_diff.append(sub)
print(min(min_diff))


II = lambda : list(map(int, input().split()))
(n, m) = II()
A = sorted(II())
print(min([A[i + n - 1] - A[i] for i in range(m - n + 1)]))


(n, m) = map(int, input().split(' '))
val = [int(x) for x in input().split()]
val.sort()
mini = 2000
for i in range(len(val) - n + 1):
	maxi = 0
	temp = val[i:i + n]
	maxi = max(temp) - min(temp)
	mini = min(maxi, mini)
print(mini)


(n, m) = [int(x) for x in input().split()]
a = input().split()
b = []
for i in range(m):
	b += [int(a[i])]
b.sort()
mini = 1000
for i in range(m - n + 1):
	mini = min(mini, int(b[i + n - 1]) - int(b[i]))
print(mini)


(n, m) = map(int, input().split())
b = list(map(int, input().split()))
b_1 = sorted(b)
minus = []
for i in range(m - n + 1):
	c = b_1[i + n - 1] - b_1[i]
	minus.append(c)
minus_1 = sorted(minus)
print(minus_1[0])


(n, m) = map(int, input().split())
amounts = [int(a) for a in input().split()]
amounts = sorted(amounts)
mindiff = float('inf')
for i in range(m - n + 1):
	diff = amounts[i + n - 1] - amounts[i]
	if diff < mindiff:
		mindiff = diff
print(mindiff)


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
f.sort()
best = 1000
for k in range(0, m - n + 1):
	best = min(best, f[k + n - 1] - f[k])
print(best)


np = list(map(int, input().split()))
n = np[0]
p = np[1]
a = list(map(int, input().split()))
a.sort()
min = 9999999
for i in range(p - n + 1):
	if min > a[i + n - 1] - a[i]:
		min = a[i + n - 1] - a[i]
print(min)


inp = input().split()
lst = input().split()
n = int(inp[0])
m = int(inp[1])
lst.sort(key=int)
ans = int(lst[n - 1]) - int(lst[0])
for i in range(m - n + 1):
	if int(lst[i + n - 1]) - int(lst[i]) < ans:
		ans = int(lst[i + n - 1]) - int(lst[i])
print(ans)


(n, m) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
Min = 1000
for i in range(0, m - n + 1):
	low = a[i]
	Min = min(a[i + n - 1] - low, Min)
print(Min)


(m, n) = map(int, input().split())
arr = list(map(int, input().split()))
arr = sorted(arr)
man = 999999
for i in range(0, n - m + 1):
	if arr[i + m - 1] - arr[i] < man:
		man = arr[i + m - 1] - arr[i]
print(man)


import sys
from sys import stdin, stdout
import math
import random
import heapq
from collections import Counter
from functools import lru_cache
try:
	for _ in range(1):
		(n, k) = map(int, input().split())
		arr = [int(i) for i in input().split()]
		arr.sort()
		mx = float('inf')
		for i in range(0, k - n + 1):
			mx = min(mx, arr[i + n - 1] - arr[i])
		print(mx)
except EOFError as e:
	print(e)


(n, m) = [int(x) for x in input().split()]
lt = sorted([int(x) for x in input().split()])
s = []
for i in range(m - n + 1):
	s.append(lt[i + n - 1] - lt[i])
print(min(s))


def main():
	(n, m) = map(int, input().split(' '))
	a = input().split(' ')
	for (i, val) in enumerate(a):
		a[i] = int(val)
	a.sort()
	first = 0
	last = n - 1
	minimum = a[last] - a[first]
	while last < len(a):
		new_min = a[last] - a[first]
		if new_min < minimum:
			minimum = new_min
		(first, last) = (first + 1, last + 1)
	print(minimum)
main()


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


(n, m) = input().split()
n = int(n)
m = int(m)
f = [int(x) for x in input().split()]
f.sort()
min = 2000
for i in range(0, m - n + 1):
	dif = f[i + n - 1] - f[i]
	if dif < min:
		min = dif
print(min)


(n, m) = [int(x) for x in input().strip().split(' ')]
a = [int(x) for x in input().strip().split(' ')]
a.sort(reverse=True)
min = a[0] - a[n - 1]
for i in range(n, m):
	if a[i - n + 1] - a[i] < min:
		min = a[i - n + 1] - a[i]
print(min)


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
f.sort()
i = 0
x = 0
y = n
all_min = []
while i <= m - n:
	new_list = f[x:y]
	minimum = max(new_list) - min(new_list)
	all_min.append(minimum)
	x += 1
	y += 1
	i += 1
print(min(all_min))


(n, m) = list(map(int, input().split()))
l = list(map(int, input().split()))
l.sort()
x = float('inf')
for i in range(m - n + 1):
	x = min(x, l[n + i - 1] - l[i])
print(x)


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
f.sort()
b = float('inf')
for i in range(m - n + 1):
	b = min(b, f[i + n - 1] - f[i])
print(b)


(n, m) = map(int, input().split())
puzzleCount = list(map(int, input().split()))
puzzleCount.sort()
res = puzzleCount[m - 1] - puzzleCount[0]
for i in range(m - n + 1):
	res = min(res, puzzleCount[i + n - 1] - puzzleCount[i])
print(res)


nm = list(map(int, input().rstrip().split()))
(n, m) = nm
f = list(map(int, input().rstrip().split()))
f.sort()
least = 1000
for i in range(1 + (m - n)):
	diff = f[i + (n - 1)] - f[i]
	if diff < least:
		least = diff
print(least)


lstResult = []
(n, m) = map(int, input().split(' '))
listPuzzels = input().split()
listPuzzels = list(map(int, listPuzzels))
listPuzzels.sort()
for i in range(0, m - n + 1):
	lstResult.append(int(listPuzzels[i + n - 1]) - int(listPuzzels[i]))
lstResult.sort()
print(lstResult[0])


I = lambda : map(int, input().split())
(n, m) = I()
f = sorted(list(I()))
k = 10000
for i in range(m - n + 1):
	k = min(k, f[n + i - 1] - f[i])
print(k)


import sys
values = [int(x) for x in sys.stdin.readline().split()]
(n_students, n_puzzles) = (values[0], values[1])
puzzle_values = [int(x) for x in sys.stdin.readline().split()]
puzzle_values.sort()
min_differences = 100000000000
for i in range(n_students - 1, len(puzzle_values)):
	difference = puzzle_values[i] - puzzle_values[i - (n_students - 1)]
	min_differences = min(min_differences, difference)
print(min_differences)


(n, t) = map(int, input().split())
s = list(map(int, input().split()))
s.sort()
m = 1000
for i in range(t - n + 1):
	m = min(m, s[n + i - 1] - s[i])
print(m)


(n, m) = [int(j) for j in input().split()]
l = [int(j) for j in input().split()]
l.sort()
md = l[-1] - l[0]
for i in range(m - n + 1):
	d = l[i + n - 1] - l[i]
	md = min(md, d)
print(md)


angka = input().split(' ')
kids = int(angka[0])
puzzle = int(angka[1])
arr = []
arr1 = []
arr2 = []
arr3 = []
total = 0
blok = input().split(' ')
for i in range(len(blok)):
	arr3.append(int(blok[i]))
arr3.sort()
k = kids - 1
for j in range(len(arr3)):
	total = arr3[k] - arr3[j]
	arr2.append(total)
	if k == puzzle - 1:
		break
	k = k + 1
arr2.sort()
print(arr2[0])


(n, m) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
for i in range(m):
	for j in range(m - 1):
		if a[j] > a[j + 1]:
			x = a[j]
			a[j] = a[j + 1]
			a[j + 1] = x
s = a[n - 1] - a[0]
for k in range(m - n + 1):
	s = min(s, a[k + n - 1] - a[k])
print(s)


(n, m) = map(int, input().split())
lst = sorted(list(map(int, input().split())))
su1 = lst[n - 1] - lst[0]
for i in range(1, m - n + 1):
	if lst[i + n - 1] - lst[i] < su1:
		su1 = lst[i + n - 1] - lst[i]
print(su1)


(n, m) = map(int, input().split())
y = list(map(int, input().split()))
s = []
(a, b, c) = (0, 0, 0)
y = sorted(y)
for i in range(len(y) - (n - 1)):
	x = []
	for j in range(n):
		x.append(y[i + j])
	a = max(x)
	b = min(x)
	s.append(a - b)
c = min(s)
print(c)


(n, m) = [int(x) for x in input().split()]
I = list(map(int, input().split()))
a = sorted(I)
print(min((j - i for (i, j) in zip(a, a[n - 1:]))))


(a, b) = map(int, input().split())
c = input().split()
d = b - a + 1
e = 0
f = 0
g = 0
ans = [0] * (b - a + 1)
for n in c:
	c[g] = int(c[g])
	g += 1
c.sort()
while d:
	ans[f] = int(c[a + e - 1]) - int(c[e])
	e += 1
	f += 1
	d -= 1
ansmin = min(ans)
print(ansmin)


input_list = []
num = 0
while True:
	if num == 2:
		break
	line = input()
	line = line.split()
	line = list(map(int, line))
	input_list.append(line)
	num += 1
input_list[1].sort()
count = 0
diffl = []
while count < input_list[0][1] - input_list[0][0] + 1:
	diff = input_list[1][count + input_list[0][0] - 1] - input_list[1][count]
	count += 1
	diffl.append(diff)
print(min(diffl))


l = [int(x) for x in input().split()]
n = l[0]
m = l[1]
l = [int(x) for x in input().split()]
l.sort()
l.reverse()
x = m - n + 1
flag = 0
for i in range(0, x):
	t = l[i] - l[i + n - 1]
	if flag == 0:
		temp = t
		flag = 1
	elif t < temp:
		temp = t
print(temp)


def mergeSort(alist):
	if len(alist) > 1:
		mid = len(alist) // 2
		left = alist[:mid]
		right = alist[mid:]
		mergeSort(left)
		mergeSort(right)
		i = 0
		j = 0
		k = 0
		while i < len(left) and j < len(right):
			if left[i] < right[j]:
				alist[k] = left[i]
				i += 1
			else:
				alist[k] = right[j]
				j += 1
			k += 1
		while i < len(left):
			alist[k] = left[i]
			i += 1
			k += 1
		while j < len(right):
			alist[k] = right[j]
			j += 1
			k += 1
rawIn = input().split()
n = int(rawIn[0])
m = rawIn[1]
numPieces = [int(x) for x in input().split()]
mergeSort(numPieces)

def findDifferences(numPieces):
	diffList = []
	i = 0
	while i < len(numPieces):
		if i > 0:
			diffList.append(numPieces[i] - numPieces[i - 1])
		i += 1
	return diffList
diffList = findDifferences(numPieces)
smallestDiff = 10001
for i in range(len(numPieces) - n + 1):
	checkDiff = numPieces[i + n - 1] - numPieces[i]
	if checkDiff < smallestDiff:
		smallestDiff = checkDiff
print(smallestDiff)


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
f.sort()
diff = [0]
for i in range(1, m):
	diff.append(diff[i - 1] + f[i] - f[i - 1])
res = []
for i in range(m - n + 1):
	res.append(diff[i + n - 1] - diff[i])
print(min(res))


def abir():
	return map(int, input().split())
s = list(abir())
p = list(abir())
p.sort()
j = 0
mn = 999999
for i in range(s[0] - 1, s[1]):
	mn = min(p[i] - p[j], mn)
	j += 1
print(mn)


(n, m) = list(map(int, input().split()))
puzzle = list(sorted(list(map(int, input().split()))))
res = 1000000.0
for i in range(m - n + 1):
	res = min(res, puzzle[i + n - 1] - puzzle[i])
if res == 1000000.0:
	print(0)
else:
	print(res)


l1 = input().split(' ')
n = int(l1[0])
m = int(l1[1])
l2 = [int(x) for x in input().split(' ')]
l2.sort()
min = 1000
if len(l2) > n:
	for k in range(0, m - n + 1):
		x = l2[k + n - 1] - l2[k]
		if x < min:
			min = x
else:
	min = l2[-1] - l2[0]
print(min)


(n, m) = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
l.sort()
re = l[n - 1] - l[0]
for i in range(1, m - n + 1):
	ree = l[i + n - 1] - l[i]
	re = min(re, ree)
print(re)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
for k in range(m - 1):
	for i in range(m - 1 - k):
		if a[i] > a[i + 1]:
			b = a[i]
			a[i] = a[i + 1]
			a[i + 1] = b
c = a[m - 1] - a[m - n]
for i in range(m - n):
	c = min(c, a[i + n - 1] - a[i])
print(c)


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


def min_diff(sizes, n):
	sizes = sorted(sizes)
	i = 0
	j = i + n - 1
	diffs = []
	while j < len(sizes):
		diffs.append(sizes[j] - sizes[i])
		i += 1
		j += 1
	j = len(sizes) - 1
	i = j - n + 1
	while i >= 0:
		diffs.append(sizes[j] - sizes[i])
		j -= 1
		i -= 1
	return min(diffs)
(n, m) = input().split()
(n, m) = (int(n), int(m))
sizes = input().split()
sizes = [int(i) for i in sizes]
print(min_diff(sizes, n))


(m, n) = map(int, input().split())
f = list(map(int, input().split()))
f.sort()
z = []
x = 1000000000.0
for i in range(n - m + 1):
	z = f[i:i + m]
	x = min(x, max(z) - min(z))
print(x)


(needing, available) = map(int, input().split())
pieces = list(map(int, input().split()))
pieces.sort()
min_diff = 100000000
i = 0
while i < len(pieces) - needing + 1:
	diff = pieces[i + needing - 1] - pieces[i]
	if diff < min_diff:
		min_diff = diff
	i += 1
print(min_diff)


import math, fractions
(n, m) = map(int, input().split())
q = [int(x) for x in input().split()]
q.sort()
ans = int(100000.0)
for i in range(m - n + 1):
	tq = q[i:i + n]
	ans = min(ans, max(tq) - min(tq))
print(ans)


(n, m) = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
res = 10 ** 100
for i in range(m - n + 1):
	res = min(res, A[n + i - 1] - A[i])
print(res)


l = list(map(int, input().split()))
(n, m) = (l[0], l[1])
l = list(map(int, input().split()))
l.sort()
i = 0
mi = float('inf')
while i + n < m + 1:
	if l[i + n - 1] - l[i] < mi:
		mi = l[i + n - 1] - l[i]
	i += 1
print(mi)


(n, m) = map(int, input().split())
li = list(map(int, input().split()))
li.sort()
mini = max(li) - min(li)
for i in range(m - n + 1):
	li1 = li[i:i + n]
	diff = max(li1) - min(li1)
	if diff < mini:
		mini = diff
print(mini)


(n, m) = map(int, input().split())
puzzles_len = sorted(list(map(int, input().split())))
output = puzzles_len[n - 1] - puzzles_len[0]
for i in range(m - n):
	output = min(puzzles_len[i + n] - puzzles_len[i + 1], output)
print(output)


from sys import stdin
(n, m) = map(int, stdin.readline().split())
a = sorted(list(map(int, stdin.readline().split())))
ans = 99999999
for i in range(m - n + 1):
	ans = min(ans, a[i + n - 1] - a[i])
print(ans)


x = input().split()
y = input().split()
n = int(x[0])
m = int(x[1])
l = []
for s in y:
	l.append(int(s))
l.sort()
pasuxi = 3000
for i in range(m - n + 1):
	c = l[i + n - 1] - l[i]
	if pasuxi > c:
		pasuxi = c
print(pasuxi)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
x = a[0]
diff = 100000
a.sort()
(i, j) = (0, n - 1)
while i < m and j < m:
	x = a[j] - a[i]
	if x < diff:
		diff = x
	i += 1
	j += 1
print(diff)


temp = list(map(int, input().split()))
n = temp[0]
m = temp[1]
mylist = list(map(int, input().split()))
min = 23232222223232
mylist.sort()
for i in range(0, len(mylist) - n + 1):
	if abs(mylist[i] - mylist[i + n - 1]) < min:
		min = abs(mylist[i] - mylist[i + n - 1])
else:
	print(min)


ins = input().strip().split(' ')
(n, m) = (int(ins[0]), int(ins[1]))
ins = [int(i) for i in input().strip().split(' ')]
ins.sort()
end = n
s = ins[end - 1] - ins[0]
min_s = s
while end <= len(ins):
	s = ins[end - 1] - ins[end - n]
	if s < min_s:
		min_s = s
	end += 1
print(min_s)


a = list(map(int, input().split()))
a1 = a[0] - 1
b = list(map(int, input().split()))
b.sort()
c = 10000
for i in range(a[1] - a1):
	if b[i + a1] - b[i] < c:
		c = b[i + a1] - b[i]
print(c)


(n, m) = (int(x) for x in input().split())
p = [int(x) for x in input().split()]
p.sort()
val = 1000
for i in range(m - n + 1):
	cur = p[n + i - 1] - p[i]
	if cur < val:
		val = cur
print(val)


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
from itertools import permutations
import heapq
I = sys.stdin.readline
alpha = 'abcdefghijklmnopqrstuvwxyz'

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def mi():
	return map(int, I().strip().split())

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	elif n <= 2:
		return True
	else:
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				return False
		return True

def main():
	(n, m) = mi()
	arr = sorted(li())
	i = 0
	j = n - 1
	ans = 10 ** 9
	while j < m:
		ans = min(ans, arr[j] - arr[i])
		i += 1
		j += 1
	print(ans)
main()


(n, m) = [int(x) for x in input().split()]
ljk = [int(x) for x in input().split()]
ljk.sort()
min = ljk[n - 1] - ljk[0]
i = 0
while i + (n - 1) < m:
	if ljk[i + (n - 1)] - ljk[i] < min:
		min = ljk[i + (n - 1)] - ljk[i]
	i += 1
print(min)


import sys
tmp = list(map(int, sys.stdin.readline().split()))
n = tmp[1]
k = tmp[0]
a = list(map(int, sys.stdin.readline().split()))
a.sort()
res = 1000111000
for i in range(0, n - k + 1):
	res = min(res, a[i + k - 1] - a[i])
print(res)


a = input()
b = input()
c = a.split()
d = b.split()
d.sort(key=float)
i = 0
min = int(d[len(d) - 1]) - int(d[0])
while i <= int(c[1]) - int(c[0]):
	if int(d[i + int(c[0]) - 1]) - int(d[i]) < min:
		min = int(d[i + int(c[0]) - 1]) - int(d[i])
	i += 1
print(min)


(n, m) = [int(x) for x in input().split()]
f = [int(x) for x in input().split()]
f.sort()
min = 1001
for i in range(m - n + 1):
	if f[i + n - 1] - f[i] < min:
		min = f[i + n - 1] - f[i]
print(min)


(n, m) = [int(x) for x in input().split()]
puzzles = sorted(list(map(int, input().split())))
k = puzzles[m - 1] - puzzles[m - n]
for i in range(m - n + 1):
	t = puzzles[i + n - 1] - puzzles[i]
	if t < k:
		k = t
print(k)


import sys
inf = 1 << 30

def solve():
	(n, m) = map(int, input().split())
	f = [int(i) for i in input().split()]
	f.sort()
	ans = inf
	for i in range(m - n + 1):
		ans = min(ans, f[i + n - 1] - f[i])
	print(ans)
solve()


(n, m) = map(int, input().split())
puzzle_list = list(map(int, input().split()))
puzzle_sort = sorted(puzzle_list)
minimum = puzzle_sort[n - 1] - puzzle_sort[0]
for i in range(m - n):
	if puzzle_sort[i + n] - puzzle_sort[i + 1] < minimum:
		minimum = puzzle_sort[i + n] - puzzle_sort[i + 1]
print(minimum)


(n, m) = map(int, input().split())
puzl = sorted(map(int, input().split()))
minDif = puzl[n - 1] - puzl[0]
for i in range(1, m - n + 1):
	if puzl[i + n - 1] - puzl[i] < minDif:
		minDif = puzl[i + n - 1] - puzl[i]
print(minDif)


s = input().split()
n = int(s[0])
m = int(s[1])
result = 9999
s = input().split()
for i in range(len(s)):
	s[i] = int(s[i])
s.sort()
for i in range(n - 1, len(s)):
	if abs(s[i] - s[i - n + 1]) < result:
		result = abs(s[i] - s[i - n + 1])
print(result)


(n, m) = map(int, input().split(' '))
l = [int(x) for x in input().split(' ')]
l = sorted(l[:m]) + l[m:]
ult = l[n - 1] - l[0]
for i in range(1, m - n + 1):
	if l[i + n - 1] - l[i] < ult:
		ult = l[i + n - 1] - l[i]
print(ult)


(n, m) = map(int, input().split())
M = sorted(list(map(int, input().split())))
x = [M[i] - M[i - n + 1] for i in range(n - 1, m)]
print(min(x))


from sys import stdin
from functools import reduce
x = [int(i) for i in stdin.read().rstrip().split()]
n = x[0]
m = x[1]
puzzles = x[2:]
puzzles.sort()
i = 0

def diff(seq):
	total = 0
	res = sum([abs(seq[i] - seq[i - 1]) for i in range(1, len(seq))])
	return res
least = float('inf')
while i <= m - n:
	least = min(least, diff(puzzles[i:i + n]))
	i += 1
print(least)


input_list = [int(i) for i in input().split()]
n = input_list[0]
m = input_list[1]
input_list = [int(i) for i in input().split()]
input_list.sort()
diff = []
for i in range(m - 1):
	diff.append(input_list[i + 1] - input_list[i])
sum_list = []
for t in range(m - n + 1):
	sum1 = 0
	for i in range(n - 1):
		sum1 += diff[t + i]
	sum_list.append(sum1)
print(min(sum_list))


inp1 = str(input())
inp = inp1.split()
n = int(inp[0])
m = int(inp[1])
arr = list(map(int, input().split()))
arr.sort()
a = []
for i in range(m - n + 1):
	b = arr[i + n - 1] - arr[i]
	a.append(b)
print(min(a))


(n, m) = map(int, input().split())
s = list((int(x) for x in input().split()))
s.sort(reverse=True)
c = []
for i in range(m - n + 1):
	t = s[i] - s[i + n - 1]
	c.append(t)
result = min(c)
print(result)


import random
import math
(n, m) = input().split()
n = int(n)
m = int(m)
puzzles = []
puzzles = list(map(int, input().split()))
puzzles.sort()
diff = 9999
counter = n - 1
while counter < m:
	if puzzles[counter] - puzzles[counter - n + 1] < diff:
		diff = puzzles[counter] - puzzles[counter - n + 1]
	counter = counter + 1
print(diff)


(n, m) = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
arr.sort()
mino = 1000000000000
for i in range(m - n + 1):
	mino = min(mino, arr[i + n - 1] - arr[i])
print(mino)


(n, m) = map(int, input().split())
p = input().split()
data1 = []
for i in range(m - 1):
	for j in range(i + 1, m):
		if int(p[i]) > int(p[j]):
			temp = p[i]
			p[i] = p[j]
			p[j] = temp
for i in range(m - (n - 1)):
	data = []
	for j in range(i, i + n):
		data += [p[j]]
	data1 += [int(data[-1]) - int(data[0])]
terkecil = data1[0]
for i in range(1, len(data1)):
	if terkecil > int(data1[i]):
		terkecil = int(data1[i])
print(terkecil)


inpList = input()
inp = inpList.split()
n = int(inp[0])
m = int(inp[1])
farr = input()
flist = farr.split()
f = []
for i in flist:
	f.append(int(i))
f.sort()
mina = f[n - 1] - f[0]

def minx(a, b):
	if a < b:
		return a
	return b
for i in range(n, m):
	mina = minx(f[i] - f[i - n + 1], mina)
print(mina)


import math
(n, m) = [int(x) for x in input().split(' ')]
A = [int(x) for x in input().split(' ')]
A.sort()
best = math.inf
for i in range(m - n + 1):
	best = min(best, A[i + n - 1] - A[i])
print(best)


nm = [int(i) for i in input().split()]
n = nm[0]
m = nm[1]
numbers = [int(i) for i in input().split()]
numbers.sort()
min1 = 10000000000
for i in range(m - n + 1):
	min1 = min(numbers[i + n - 1] - numbers[i], min1)
print(min1)


(n, m) = [int(x) for x in input().split()]
list1 = [int(x) for x in input().split()]
list1.sort()
num = list1[n - 1] - list1[0]
for i in range(m - n):
	if list1[i + n - 1] - list1[i] < list1[i + n] - list1[i + 1] and list1[i + n - 1] - list1[i] < num:
		num = list1[i + n - 1] - list1[i]
	elif list1[i + n - 1] - list1[i] >= list1[i + n] - list1[i + 1] and list1[i + n] - list1[i + 1] < num:
		num = list1[i + n] - list1[i + 1]
print(num)


from collections import Counter
line1 = list(map(int, input().split()))
line2 = list(map(int, input().split()))
(demand, supply) = (line1[0], line1[1])
prices = sorted(line2)
min_diff = max(prices) - min(prices)
for i in range(supply - demand + 1):
	diff = prices[i:i + demand]
	min_diff = min(min_diff, max(diff) - min(diff))
print(min_diff)


(n, m) = list(map(int, input().split()))
lst = list(map(int, input().split()))
if n < m:
	l = m
	h = 1
	while h < l // 3:
		h += 3 * h + 1
	while h >= 1:
		for i in range(h, l):
			for j in range(i, h - 1, -h):
				if lst[j] < lst[j - h]:
					(lst[j], lst[j - h]) = (lst[j - h], lst[j])
		h //= 4
	mini = 10000000
	for i in range(0, l):
		if len(lst[i:i + n]) == n:
			sumi = lst[i:i + n][-1] - lst[i:i + n][0]
		if sumi < mini:
			mini = sumi
	print(mini)
else:
	print(max(lst) - min(lst))


import sys

def process_line(lines):
	tmp = lines[0].split()
	n = int(tmp[0])
	m = int(tmp[1])
	items = []
	for obj in lines[1].split():
		items.append(int(obj))
	return (n, m, items)

def read_line():
	out_list = []
	for line in sys.stdin:
		out_list.append(line)
	return out_list

def codeforce():
	lines = read_line()
	(n, m, items) = process_line(lines)
	items.sort()
	min_val = 1e+100
	for (l, h) in zip(items, items[n - 1:]):
		if h - l < min_val:
			min_val = h - l
	print(min_val)
codeforce()


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	(k, n) = LI()
	a = sorted(LI())
	r = inf
	for i in range(n - k + 1):
		t = a[i + k - 1] - a[i]
		if r > t:
			r = t
	return r
print(main())


(n, m) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.sort()
best = 2147483647
for i in range(m):
	j = i + n - 1
	if j >= m:
		break
	best = min(best, a[j] - a[i])
print(best)


from collections import Counter
(n, m) = map(int, input().split())
l = list(map(int, input().split()))
ans = []
l.sort()
for i in range(m):
	try:
		ans.append(l[i + n - 1] - l[i])
	except:
		pass
print(min(ans))


(n, m) = [int(x) for x in input().split()]
f = [int(x) for x in input().split()]
f.sort(reverse=True)
ans = f[0] - f[n - 1]
val = f[0] - f[n - 1]
for i in range(m - n + 1):
	val = f[i] - f[i + n - 1]
	ans = min(val, ans)
print(ans)


(n, m) = input().split()
puzzles = input().split()
n = int(n)
m = int(m)
i = 0
while i < m:
	puzzles[i] = int(puzzles[i])
	i += 1
puzzles.sort()
start = 0
dif = puzzles[m - 1] - puzzles[0]
while m + 1 - start > n:
	liste = puzzles[start:n + start]
	new_dif = liste[n - 1] - liste[0]
	if new_dif < dif:
		dif = new_dif
	start += 1
print(dif)


s = input().split()
a = int(s[0])
b = int(s[1])
st = input().split()
mat = []
point = 100000
for i in range(len(st)):
	st[i] = int(st[i])
	mat.append(st[i])
mat = sorted(mat)
for i in range(len(mat) - a + 1):
	sat = list(mat[i:a + i])
	if max(sat) - min(sat) < point:
		point = max(sat) - min(sat)
	sat = []
if point != 100000:
	print(point)
else:
	print(0)


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
f.sort()
max_val = 1001
for i in range(m - n + 1):
	dif = f[i + n - 1] - f[i]
	if dif < max_val:
		max_val = dif
print(max_val)


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
(N, M) = map(int, input().split())
F = [int(x) for x in input().split()]
F.sort()
d = M - N
ans = float('inf')
for left in range(d + 1):
	right = d - left
	ans = min(ans, F[M - right - 1] - F[left])
print(ans)


A = input().split()
n = int(A[0])
m = int(A[1])
L = input().split()
L = [int(i) for i in L]
L.sort()
tot = m - n + 1
S = [0] * tot
for i in range(0, tot):
	S[i] = L[i + n - 1] - L[i]
print(min(S))


from sys import stdin
i = 1
for line in stdin:
	if i == 1:
		(N, M) = [int(k) for k in line.split()]
	else:
		boxes = [int(k) for k in line.split()]
	i += 1
boxes.sort()
for i in range(M - N + 1):
	if i == 0:
		minimum = boxes[i + N - 1] - boxes[i]
	elif boxes[i + N - 1] - boxes[i] < minimum:
		minimum = boxes[i + N - 1] - boxes[i]
print(minimum)


a = input().split()
arr = input().split()
i = 0
for ch in arr:
	arr[i] = int(ch)
	i = i + 1
n = int(a[0])
m = int(a[1])
arr.sort()
min = arr[n - 1] - arr[0]
for i in range(m - n + 1):
	diff = arr[n + i - 1] - arr[i]
	if diff < min:
		min = diff
print(str(min))


(n, m) = map(int, input().split())
ar = list(map(int, input().split()))
ar.sort(reverse=1)
mn = ar[0] - ar[n - 1]
for i in range(m - n + 1):
	mn = min(mn, ar[i] - ar[n - 1 + i])
print(mn)


def seperateints(x):
	k = ''
	l = []
	for i in x:
		if i == ' ':
			l.append(int(k))
			k = ''
			continue
		k = k + i
	l.append(int(k))
	return l

def luckynum(x):
	for i in x:
		if i != '4' and i != '7':
			return False
	return True
l = seperateints(input())
w = seperateints(input())
w = sorted(w)
mini = 1000
for i in range(l[1]):
	if i + l[0] - 1 >= l[1]:
		break
	if w[i + l[0] - 1] - w[i] < mini:
		mini = w[i + l[0] - 1] - w[i]
print(mini)


(n, m) = list(map(int, input().split()))
lst = list(map(int, input().split()))
lst.sort()
p = []
for i in range(m - n + 1):
	lst1 = lst[i:n + i]
	p.append(abs(lst1[0] - lst1[len(lst1) - 1]))
print(min(p))


(students, numberOfPuzzles) = [int(i) for i in input().split()]
list_of_puzzles = [int(j) for j in input().split()]
list_of_puzzles.sort()
minimum_number = 1000000000000000000
currrent_number = 1000000000000000000000
for i in range(0, len(list_of_puzzles) - students + 1):
	currrent_number = list_of_puzzles[i + (students - 1)] - list_of_puzzles[i]
	if currrent_number < minimum_number:
		minimum_number = currrent_number
print(minimum_number)


(n, k) = [int(__) for __ in input().strip().split()]
arr = [int(__) for __ in input().strip().split()]
arr.sort()
ans = arr[-1] - arr[0]
for i in range(len(arr) - n + 1):
	ans = min(ans, arr[i + n - 1] - arr[i])
print(ans)


(n, m) = map(int, input().split())
num = [int(x) for x in input().split()]
num.sort()
C = num[m - 1] - num[0]
for i in range(0, m - n + 1):
	C1 = num[i + n - 1] - num[i]
	C = min(C, C1)
print(C)


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


(n, m) = map(int, input().split())
z = list(map(int, input().split()))
z = sorted(z)
l = []
i = 0
while n + i <= m:
	p = z[i:n + i]
	p = sorted(p)
	t = p[-1] - p[0]
	l.append(t)
	i = i + 1
print(min(l))


def main():
	(n, m) = map(int, input().split())
	data = list(map(int, input().split()))
	data.sort()
	mn = pow(10, 4)
	for i in range(len(data) - n + 1):
		x = data[i + n - 1] - data[i]
		mn = min(x, mn)
		pass
	print(mn)
	pass
main()


(n, m) = map(int, input().split())
s = map(int, input().split())
s = list(s)
s.sort()
j = 0
i = n - 1
m1 = 10000
while i < m:
	if m1 > s[i] - s[j]:
		m1 = s[i] - s[j]
	i += 1
	j += 1
print(m1)


(n, m) = map(int, input().split())
f = sorted([int(i) for i in input().split()])
b = max(f) - min(f)
for i in range(m - n + 1):
	c = f[i + n - 1] - f[i]
	if b > c:
		b = c
print(b)


import itertools

def mixture(val_list, min_val=99999999999999999999999999):
	if val_list == []:
		return min_val
	else:
		pass
	for jj in val_list[1:]:
		if abs(val_list[0] - jj) < min_val:
			min_val = abs(val_list[0] - jj)
		else:
			pass
	return mixture(val_list[1:], min_val)

def main():
	[n, m] = [int(i) for i in input('').split()]
	val_list = [int(i) for i in input('').split()]
	val_list.sort()
	val_list.reverse()
	min_val = 999999999999999999999
	for i in range(0, m - n + 1):
		if val_list[i:i + n][0] - val_list[i:i + n][-1] < min_val:
			min_val = val_list[i:i + n][0] - val_list[i:i + n][-1]
		else:
			pass
	print('%d' % min_val)
main()


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


(students, gifts) = map(int, input().split(' '))
input_list = list(map(int, input().split(' ')))
sorted_list = sorted(input_list)
j = []
for i in range(len(input_list)):
	if students + i <= len(input_list):
		j.append(sorted_list[students - 1 + i] - sorted_list[i])
print(min(j))


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
d = 1201212121212
for i in range(m - n + 1):
	d = min(d, max(a[i:i + n]) - min(a[i:i + n]))
print(d)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
s = a[n - 1]
for i in range(m - n + 1):
	if a[i + n - 1] - a[i] < s:
		s = a[i + n - 1] - a[i]
print(s)


array = []
(n, m) = map(int, input().split())
string = list(map(int, input().split()))
for i in range(0, len(string)):
	array.append(int(string[i]))
array.sort()
for i in range(0, m):
	if array.count(array[i]) >= n:
		break
if array.count(array[i]) >= n:
	print(0)
else:
	minimum = array[n - 1] - array[0]
	i = 0
	while n - 1 + i < m:
		if array[n - 1 + i] - array[i] < minimum:
			minimum = array[n - 1 + i] - array[i]
		i += 1
	print(minimum)


(n, m) = map(int, input().split())
puzzles = [int(x) for x in input().split()]
puzzles = sorted(puzzles)
mini = 1001
for i in range(0, m - n + 1):
	mini = min(mini, puzzles[i + n - 1] - puzzles[i])
print(str(mini))


(studentN, puzzleN) = input().split(' ')
studentN = int(studentN)
puzzleN = int(puzzleN)
puzzle = [int(x) for x in input().split(' ')]
puzzle.sort()
Min = 9999
for i in range(studentN - 1, puzzleN):
	if puzzle[i] - puzzle[i - studentN + 1] < Min:
		Min = puzzle[i] - puzzle[i - studentN + 1]
print(Min)


(n, m) = map(int, input().split())
L = list(map(int, input().split()))
L = sorted(L)
mi = L[n - 1] - L[0]
i = 0
j = n - 1
while j < m:
	k = L[j] - L[i]
	if k < mi:
		mi = k
	i = i + 1
	j = j + 1
print(mi)


(n, m) = map(int, input().split())
x = [int(t) for t in input().split()]
x.sort()
d = x[n - 1] - x[0]
for i in range(m - n):
	d = min(d, x[n + i] - x[i + 1])
print(d)


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


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


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l = sorted(l)
newl = []
for i in range(0, len(l) - n + 1):
	newl.append(l[i + n - 1] - l[i])
print(min(newl))


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
i = 0
answer = 10 ** 18
while i + n - 1 < m:
	answer = min(answer, a[i + n - 1] - a[i])
	i += 1
print(answer)


(t, s) = map(int, input().split())
j = list(map(int, input().split()))
r = sorted(j)
x = list()
n = 0
for i in range(s - t + 1):
	x.append(r[i + t - 1] - r[i])
print(min(x))


(n, m) = list(map(int, input().split()))
f = list(map(int, input().split()))
for i in range(m):
	k = 0
	for j in range(1, m - i):
		if f[j] > f[k]:
			k = j
	if k != m - 1 - i:
		(f[k], f[m - 1 - i]) = (f[m - 1 - i], f[k])
k = 0
for i in range(1, m - n + 1):
	if f[n - 1 + i] - f[i] < f[n - 1 + k] - f[k]:
		k = i
print(f[n - 1 + k] - f[k])


import sys
it = iter(sys.stdin.read().splitlines())
(n, m) = [int(x) for x in next(it).split(' ')]
pieces = [int(x) for x in next(it).split(' ')]
pieces.sort()
result = pieces[-1]
for i in range(m - n + 1):
	difference = pieces[i + n - 1] - pieces[i]
	if difference < result:
		result = difference
print(result)


(n, m) = [int(x) for x in input().split()]
f = [int(x) for x in input().split()]
f = sorted(f)
x = 1000
for i in range(0, m - n + 1):
	if f[i + n - 1] - f[i] < x:
		x = f[i + n - 1] - f[i]
print(x)


def sort(a):
	n = len(a)
	for i in range(n):
		for j in range(i):
			if int(a[i]) < int(a[j]):
				b = a[i]
				a[i] = a[j]
				a[j] = b
	return a
a = list(input().split())
k = int(a[0])
n = int(a[1])
a = list(input().split())
a = sort(a)
d = int(a[n - 1])
for i in range(n - k + 1):
	if int(a[i + k - 1]) - int(a[i]) < d:
		d = int(a[i + k - 1]) - int(a[i])
print(d)


class CodeforcesTask337ASolution:

	def __init__(self):
		self.result = ''
		self.n_m = []
		self.puzzles = []

	def read_input(self):
		self.n_m = [int(x) for x in input().split(' ')]
		self.puzzles = [int(x) for x in input().split(' ')]

	def process_task(self):
		self.puzzles.sort()
		min_diff = 1001
		for x in range(self.n_m[1] - self.n_m[0] + 1):
			min_diff = min(min_diff, max(self.puzzles[x:x + self.n_m[0]]) - min(self.puzzles[x:x + self.n_m[0]]))
		self.result = str(min_diff)

	def get_result(self):
		return self.result
Solution = CodeforcesTask337ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


(n, m) = map(int, input().split())
puzzles = [int(i) for i in input().split()]
puzzles.sort()
best = 1000000000.0
for i in range(m - n + 1):
	smallest = puzzles[i]
	largest = puzzles[i + n - 1]
	best = min(best, largest - smallest)
print(best)


temp = input().split()
n = int(temp[0])
m = int(temp[1])
a = input().split()
for i in range(len(a)):
	a[i] = int(a[i])
k = 1
while k < len(a):
	for i in range(len(a) - k):
		if a[i] > a[i + 1]:
			(a[i], a[i + 1]) = (a[i + 1], a[i])
	k += 1
min = a[n - 1] - a[0]
for i in range(m - n + 1):
	if a[n - 1 + i] - a[i] < min:
		min = a[n - 1 + i] - a[i]
print(abs(min))


try:
	(x, y) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	Min = 10 ** 9
	for n in range(x - 1, len(l)):
		temp = l[n] - l[n - (x - 1)]
		if temp < Min:
			Min = temp
	print(Min)
except:
	pass


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
mi = 10 ** 9
for i in range(m - n + 1):
	dif = l[i + n - 1] - l[i]
	if dif < mi:
		mi = dif
print(mi)


def foo(n, m, l):
	sorted_list = sorted(list(map(int, l)))
	difference = []
	for i in range(m):
		if n + i <= m:
			difference.append(sorted_list[n - 1 + i] - sorted_list[i])
	return sorted(difference)[0]
nm = input()
x = nm.split(' ')
ll = input()
puzzles = ll.split(' ')
print(foo(int(x[0]), int(x[1]), puzzles))


A = input().split()
n = int(A[0])
m = int(A[1])
B = input().split()
for (i, a) in enumerate(B):
	B[i] = int(a)
B.sort()
P = []
for i in range(m - n + 1):
	c = int(B[i + n - 1]) - int(B[i])
	P.append(c)
print(min(P))


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


a = list(map(int, input().split()))
m = list(map(int, input().split()))
m = sorted(m)
l = 1000
for i in range(a[1] - a[0] + 1):
	l = min(m[i + a[0] - 1] - m[i], l)
print(l)


from sys import stdin
(a, p) = [[int(y) for y in x.rstrip().split()] for x in stdin.readlines()]
s = sorted(p)
(l, n) = (a[0] - 1, a[1] - 1)
r = [s[i + 1] - s[i] for i in range(n)]
print(min((sum(r[x:x + l]) for x in range(n - l + 1))))


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


n = int(input().split()[0])
z = sorted(list(map(int, input().split())))
mini = 10000000000000
for x in range(len(z) - n + 1):
	if z[x + n - 1] - z[x] < mini:
		mini = z[x + n - 1] - z[x]
print(mini)


(n, m) = [int(i) for i in input().split()]
list = []
for j in input().split():
	list.append(int(j))
list.sort()
if m != n:
	minus = []
	for i in range(m - n + 1):
		minus.append(list[i + n - 1] - list[i])
	print(min(minus))
else:
	print(list[m - 1] - list[0])


TN = 1

def solution():
	(n, m) = map(int, input().split())
	f = sorted(list(map(int, input().split())), reverse=True)
	ans = []
	for i in range(m - n + 1):
		ans.append(f[i] - f[n - 1 + i])
	print(min(ans))
while TN != 0:
	solution()
	TN -= 1


(n, m) = map(int, input().split())
lst = sorted(list(map(int, input().split())))
min_diff = lst[n - 1] - lst[0]
for x in range(n, m):
	min_diff = min(min_diff, lst[x] - lst[x - n + 1])
print(min_diff)


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
mi = float('inf')
for i in range(m - n + 1):
	if abs(arr[i] - arr[i + n - 1]) < mi:
		mi = abs(arr[i] - arr[i + n - 1])
print(mi)


first_line = list(map(int, input().split()))
second_line = list(map(int, input().split()))
temporary = []
results = []
second_line.sort()
for i in range(1 + abs(first_line[0] - first_line[1])):
	results.append(second_line[i + first_line[0] - 1] - second_line[i])
print(min(results))


import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

def inp():
	return int(input())

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

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
(n, m) = invr()
a = inlist()
a = sorted(a)
res = 1000000000
for i in range(m - n + 1):
	res = min(res, a[i + n - 1] - a[i])
print(res)


nm = input().split()
n = int(nm[0])
m = int(nm[1])
s = [int(x) for x in input().strip().split()]
s.sort(reverse=True)
i = 0
mind = 10000
while i <= len(s) - n:
	diff = s[i] - s[i + n - 1]
	if diff < mind:
		mind = diff
	i = i + 1
print(mind)


x = list(map(int, input().split(' ')))
y = list(map(int, input().split(' ')))
y.sort(reverse=True)
i = 0
ans = []
diff = x[1] - x[0]
while i != diff + 1:
	fi = 0
	fi = y[i] - y[i + (x[0] - 1)]
	ans.append(fi)
	i = i + 1
print(min(ans))


[a, b] = [int(x) for x in input().split()]
N = [int(x) for x in input().split()]
N.sort(reverse=1)
print(min([N[x] - N[x + a - 1] for x in range(b + 1 - a)]))


inp = [int(x) for x in input().split(' ')]
n = inp[0]
m = inp[1]
xs = [int(x) for x in input().split(' ')]
xs.sort()
score = 1000000000
for i in range(0, len(xs) - n + 1):
	score = min(score, xs[i + n - 1] - xs[i])
print(score)


student_no = input()
puzzle = input()
student_puzl = student_no.split()
puzzle_no = puzzle.split()
puzzles = [int(i) for i in puzzle_no]
puzzles.sort()
min_dif = max(puzzles) - min(puzzles)
diff = int(student_puzl[1]) - int(student_puzl[0])
final = int(student_puzl[0])
for i in range(diff + 1):
	selected = puzzles[i:final]
	final += 1
	seltd_dif = max(selected) - min(selected)
	if seltd_dif < min_dif:
		min_dif = seltd_dif
print(min_dif)


import sys
n_and_m = input().split()
n = int(n_and_m[0])
m = int(n_and_m[1])
puzzles = input().split()
puzzles = [int(i) for i in puzzles]
puzzles.sort()
currentDifference = float('inf')
for i in range(0, m):
	if i + n - 1 < m:
		currentDifference = min(currentDifference, puzzles[i + n - 1] - puzzles[i])
	else:
		break
print(currentDifference)


def main():
	from sys import stdin, stdout
	(n, m) = map(int, stdin.readline().split())
	li = sorted(list(map(int, stdin.readline().split())))
	minim = 100000
	for i in range(m - n + 1):
		sub = li[i:i + n]
		d = 0
		for i in range(1, len(sub)):
			d += sub[i] - sub[i - 1]
		minim = min(minim, d)
	stdout.write(str(minim))
main()


(n, m) = map(int, input().split())
ar = input()
A = list(map(int, ar.split(' ')))
B = sorted(A)
mn = 1000000000
for i in range(m - n + 1):
	mn = min(mn, B[i + n - 1] - B[i])
print(mn)


(n, m) = [int(i) for i in input().split()]
a_s = [int(i) for i in input().split()]
a_s.sort()
min_p = a_s[-1] - a_s[0]
for i in range(len(a_s) - n + 1):
	min_p = min(min_p, a_s[i + n - 1] - a_s[i])
print(min_p)


import sys
import math
(n, m) = sys.stdin.readline().strip().split()
n = int(n)
m = int(m)
p = sorted([int(x) for x in sys.stdin.readline().strip().split()])
ans = 10000000000000000
for i in range(0, m - n + 1):
	ans = min(ans, p[i + n - 1] - p[i])
print(ans)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
l = m - n
z = []
a.sort(reverse=True)
if l == 0:
	print(max(a) - min(a))
else:
	for i in range(l + 1):
		temp = a[i:i + n]
		z.append(a[i] - a[i + n - 1])
	print(min(z))


(n, m) = input().split()
list_o = input().split()
n = int(n)
m = int(m)
list_m = list()
for x in list_o:
	list_m.append(int(x))
list_m.sort(reverse=True)
k = list_m[0] - list_m[m - 1]
for i in range(0, m - n + 1):
	t = list_m[i] - list_m[i + n - 1]
	k = min(k, t)
print(k)


(n, m) = map(int, input().split())
f = sorted(map(int, input().split()))
mn = f[-1]
for i in range(m - n + 1):
	if f[i + n - 1] - f[i] < mn:
		mn = f[i + n - 1] - f[i]
print(mn)


(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
if n == m:
	x = max(a)
	y = min(a)
	print(x - y)
else:
	ans = a[n - 1] - a[0]
	for i in range(0, m - n + 1):
		if a[i + n - 1] - a[i] < ans:
			ans = a[i + n - 1] - a[i]
	print(ans)


(n, m) = map(int, input().split())
L = list(map(int, input().split(maxsplit=m)))
diff = 1000
L = sorted(L)
for i in range(m - n + 1):
	diff = min(diff, L[i + n - 1] - L[i])
print(diff)


(n, m) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.sort()
min = 100000
for i in range(m - n + 1):
	if a[i + n - 1] - a[i] < min:
		min = a[i + n - 1] - a[i]
print(min)


(n, m) = map(int, input().split())
T = list(map(int, input().split()))
T.sort()
t = T[n - 1] - T[0]
for i in range(m - n):
	if t > T[i + n] - T[i + 1]:
		t = T[i + n] - T[i + 1]
	else:
		t = t
print(t)


(n, m) = map(int, input().split())
lst = sorted([int(i) for i in input().split()])
big = 1000000
for i in range(m - n + 1):
	if lst[n - 1 + i] - lst[i] < big:
		big = lst[n - 1 + i] - lst[i]
print(big)


a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
b.sort()
arr = []
for i in range(a[1] - a[0] + 1):
	rng = b[i:a[0] + i]
	diff = max(rng) - min(rng)
	arr.append(diff)
print(min(arr))


import sys

def smallestDiff(lst, n, m):
	slst = sorted(lst)
	s = sys.maxsize
	for i in range(m - n + 1):
		if slst[n - 1 + i] - slst[i] < s:
			s = slst[n - 1 + i] - slst[i]
	return s
(n, m) = map(int, input().split())
mlst = list(map(int, input().split()))
ans = smallestDiff(mlst, n, m)
print(ans)


a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
b.sort()
minV = 1000
for i in range(0, a[1] - a[0] + 1):
	if minV > b[i + a[0] - 1] - b[i]:
		minV = b[i + a[0] - 1] - b[i]
print(minV)


(n, m) = map(int, input().split())
p = [int(x) for x in input().split()]
p = sorted(p)
if n == m:
	print(p[n - 1] - p[0])
else:
	q = []
	for i in range(0, m - n + 1):
		q.append(p[i + n - 1] - p[i])
	print(min(q))


(n, m) = [int(inp) for inp in input().strip().split()]
sorted_puzzle_sizes = sorted([int(inp) for inp in input().strip().split()])
curr_min = sorted_puzzle_sizes[n - 1] - sorted_puzzle_sizes[0]
for i in range(m - n + 1):
	if abs(sorted_puzzle_sizes[i + n - 1] - sorted_puzzle_sizes[i]) < curr_min:
		curr_min = abs(sorted_puzzle_sizes[i + n - 1] - sorted_puzzle_sizes[i])
print(curr_min)


(n, m) = map(int, input().split())
li = list(map(int, input().split()))
li.sort()
min = li[0]
max = li[-1]
diff = max - min
if n == m:
	print(diff)
else:
	i = 0
	while i <= m - n:
		if diff > li[i + n - 1] - li[i]:
			diff = li[i + n - 1] - li[i]
		i += 1
	print(diff)


(z, x) = [int(a) for a in input().split()]
c = []
c = [int(a) for a in input().split()]
c.sort()
v = 100000000000000
b = z - 1
z -= 1
while b < x:
	v = min(v, c[b] - c[b - z])
	b += 1
print(v)


def calc(n, m, a):
	ans = 100000000
	a.sort()
	for i in range(m - n + 1):
		ans = min(ans, a[i + n - 1] - a[i])
	print(ans)
(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
calc(n, m, a)


def main():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	res = 0
	sum = 99999999
	for i in range(m - n + 1):
		if a[i + n - 1] - a[i] < sum:
			sum = a[i + n - 1] - a[i]
			res = i
	print(a[res + n - 1] - a[res])
main()


l1 = input().split()
n = int(l1[0])
m = int(l1[1])
l = [int(x) for x in input().split()]
l = sorted(l)
l2 = []
for i in range(0, m - n + 1):
	l2.append(int(l[i + n - 1]) - int(l[i]))
print(min(l2))


(n, m) = [int(i) for i in input().split(' ')]
a = [int(i) for i in input().split(' ')]
a.sort()
ans = a[n - 1] - a[0]
for i in range(0, m - n + 1):
	tmp = a[n + i - 1] - a[i]
	if tmp < ans:
		ans = tmp
print(ans)


def main():
	(n, m) = map(int, input().split())
	x = list(map(int, input().split()))
	x.sort()
	i = 0
	result = 2 ** 32
	while i + n <= m:
		y = x[i:i + n]
		result = min(result, max(y) - min(y))
		i += 1
	print(result)
main()


(n, m) = map(int, input().split())
a = list((int(x) for x in input().split()))
a.sort()
max = 1000
for i in range(n - 1, m):
	if max > a[i] - a[i - n + 1]:
		max = a[i] - a[i - n + 1]
print(max)


__author__ = 'myduomilia'
(n, m) = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr.sort()
ans = 1000000000
for i in range(m - n + 1):
	ans = min(ans, arr[i + n - 1] - arr[i])
print(ans)


n = [int(n) for n in input().split()]
arr = [int(x) for x in input().split()]
array = sorted(arr)
c = []
i = 0
for i in range(n[1] - n[0] + 1):
	diff = array[i + n[0] - 1] - array[i]
	c.append(diff)
x = min(c)
xx = abs(x)
print(xx)


(n, m) = map(int, input().split())
fi = [int(k) for k in input().split()]
fi.sort()
x = fi[n - 1] - fi[0]
for i in range(1, m - n + 1):
	X = fi[i + n - 1] - fi[i]
	x = min(x, X)
print(x)


(n, m) = map(int, input().split())
t = list(map(int, input().split()))
t.sort()
print(min([t[i + n - 1] - t[i] for i in range(0, m - n + 1)]))


x = [0, 0]
x = input().split()
x[0] = int(x[0])
x[1] = int(x[1])
a = []
for i in range(0, x[1]):
	a.append(0)
a = input().split()
for i in range(0, x[1]):
	a[i] = int(a[i])
for i in range(0, x[1]):
	for j in range(i, x[1]):
		if a[i] > a[j]:
			(a[i], a[j]) = (a[j], a[i])
b = []
for i in range(0, x[1] + 1 - x[0]):
	m = a[i + x[0] - 1] - a[i]
	b.append(m)
print(min(b))


from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

def read_int():
	return int(stdin.readline())

def read_ints():
	return [int(x) for x in stdin.readline().split()]

def read_str():
	return input()

def read_strs():
	return [x for x in stdin.readline().split()]
(n, m) = read_ints()
arr = sorted(read_ints())
arrs = [b - a for (a, b) in zip(arr, arr[n - 1:])]
print(min(arrs))


(n, m) = map(int, input().split())
s = input().split()
i = 0
lst = []
while i < m:
	lst.append(int(s[i]))
	i += 1
lst.sort()
k = 0
lst2 = []
while k <= m - n:
	lst2.append(max(lst[k:n + k]) - min(lst[k:n + k]))
	k += 1
print(min(lst2))


[n, m] = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr.sort()
mn = arr[m - 1] - arr[0]
for idx in range(m - n + 1):
	mn = min(mn, arr[idx + n - 1] - arr[idx])
print(mn)


line = input()
(N, M) = line.split()
(n, m) = (int(N), int(M))
list1 = [int(i) for i in input().split()]
list1.sort()
list2 = []
for i in range(0, m - n + 1, 1):
	list2.append(list1[i + n - 1] - list1[i])
print(min(list2))


class Solver:

	def main(self):
		(n, m) = [int(item) for item in input().strip().split()]
		a = sorted([int(item) for item in input().strip().split()])
		ans = 10 ** 10
		for i in range(m - n + 1):
			ans = min(ans, a[i + n - 1] - a[i])
		print(ans)
Solver().main()


(a, b) = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
d = 1000
for x in range(b - a + 1):
	if c[x + a - 1] - c[x] <= d:
		d = c[x + a - 1] - c[x]
print(d)


import math

def solve(arr, n, m):
	arr.sort()
	h = m - 1
	m = math.inf
	while h > n - 2:
		if arr[h] - arr[h - n + 1] < m:
			m = arr[h] - arr[h - n + 1]
		h -= 1
	return m
(n, m) = list(map(int, input().strip().split()))
arr = list(map(int, input().strip().split()))
result = solve(arr, n, m)
print(result)


(n, m) = [int(x) for x in input().split()]
a = sorted([int(x) for x in input().split()])
Min = a[n - 1] - a[0]
for i in range(m - n + 1):
	x = a[i + n - 1] - a[i]
	if x < Min:
		Min = x
print(Min)


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from bisect import bisect_left
from bisect import bisect_right
from collections import deque

def L():
	return list(map(int, stdin.readline().split()))

def In():
	return map(int, stdin.readline().split())

def I():
	return int(stdin.readline())
P = 1000000007
(n, m) = In()
arr = L()
arr.sort()
mn = P
for i in range(m - n + 1):
	mn = min(mn, arr[n + i - 1] - arr[i])
print(mn)


(n, m) = [int(s) for s in input().split(' ')]
list_f = [int(s) for s in input().split(' ')]
list_f.sort(reverse=True)
list_diff = []
for i in range(m - n + 1):
	list_diff.append(max(list_f[i:i + n]) - min(list_f[i:i + n]))
print(min(list_diff))


z = list(input().split())
n = int(z[0])
m = int(z[1])
a = list(input().split())
b = []
for i in range(m):
	b.append(int(a[i]))
c = sorted(b)
low = c[n - 1] - c[0]
for i in range(m - n + 1):
	if c[i + n - 1] - c[i] < low:
		low = c[i + n - 1] - c[i]
print(low)


(a, b) = map(int, input().split(' '))
s = [int(x) for x in input().split(' ')]
s.sort()
l = 1000000.0
for i in range(len(s) - a + 1):
	l = min(l, s[i + a - 1] - s[i])
print(l)


(n, m) = list(map(int, input().split()))
lst = list(map(int, input().split()))
lst.sort()
minimum = float('Inf')
for i in range(m - n + 1):
	if lst[i + n - 1] - lst[i] < minimum:
		minimum = lst[i + n - 1] - lst[i]
print(minimum)


(n, m) = map(int, input().split())
a = [0 for i in range(100)]
s = input()
i = 0
t = 0
while i < len(s):
	if i == len(s):
		break
	if s[i] == ' ':
		i += 1
	else:
		x = ''
		while s[i] != ' ' and i < len(s):
			x = x + s[i]
			i += 1
			if i >= len(s):
				break
		a[t] = int(x)
		t += 1
for i in range(m - 1):
	for j in range(i + 1, m):
		if a[i] > a[j]:
			t = a[i]
			a[i] = a[j]
			a[j] = t
x = 10000
for i in range(n - 1, m):
	if a[i] - a[i - n + 1] < x:
		x = a[i] - a[i - n + 1]
print(x)


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
i = 0
res = 9999999
while i + n - 1 < m:
	res = min(res, arr[i + n - 1] - arr[i])
	i = i + 1
print(res)


(n, m) = input().split()
(n, m) = (int(n), int(m))
lis = input().split()
for i in range(m):
	lis[i] = int(lis[i])
lis.sort()
d = lis[n - 1] - lis[0]
for i in range(1, m - n + 1):
	if lis[i + n - 1] - lis[i] < d:
		d = lis[i + n - 1] - lis[i]
print(d)


(n, m) = [int(x) for x in input().split()]
f = sorted([int(x) for x in input().split()])
diff = 100000
for i in range(m - n + 1):
	if f[i + n - 1] - f[i] < diff:
		diff = f[i + n - 1] - f[i]
print(diff)


(n, m) = map(int, input().split())
f = sorted(list(map(int, input().split())))
mn = 1000
for i in range(m - n + 1):
	diff = f[i + n - 1] - f[i]
	mn = min(mn, diff)
print(mn)


(n, m) = input().split()
(n, m) = (int(n), int(m))
lst = list(map(int, input().split()))
lst = sorted(lst)
mx = lst[-1] - lst[0]
for i in range(len(lst)):
	for j in range(i + n - 1, len(lst)):
		cur = lst[j] - lst[i]
		if cur < mx:
			mx = cur
print(mx)


l = lambda : map(int, input().split())
(n, k) = l()
a = sorted(l())
print(min((j - i for (i, j) in zip(a, a[n - 1:]))))


import sys
from collections import *
from math import *
import re

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	c = 0
	for i in range(2, n):
		if prime[i]:
			c += 1
	return c

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

def inp():
	return map(int, input().split())

def lcm(a, b):
	return a * b / gcd(a, b)

def iseven(n):
	return [False, True][0 if n % 2 else 1]
max_int = sys.maxsize
mod = 10 ** 9 + 7
(n, m) = inp()
arr = sorted(inp_arr())
ans = max_int
for i in range(m - n + 1):
	ans = min(ans, arr[n + i - 1] - arr[i])
print(ans)


(n, m) = [int(x) for x in input().split()]
puzzles = [int(x) for x in input().split()]
L = sorted(puzzles)
num = L[-1] - L[0]
for i in range(m - n + 1):
	num = min(num, L[i + n - 1] - L[i])
print(num)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
r = float('inf')
for i in range(m - n + 1):
	if l[i + n - 1] - l[i] < r:
		r = l[i + n - 1] - l[i]
print(r)


(m, n) = [int(m) for m in input().split()]
a = sorted([int(m) for m in input().split()])
c = []
i = 0
while i + (m - 1) < n:
	c.append(abs(a[i] - a[i + m - 1]))
	i += 1
print(min(c))


(n, m) = map(int, input().split())
f = [int(x) for x in input().split()]
f.sort()
ans = 1000
i = 0
while i + n <= m:
	ans = min(ans, f[i + n - 1] - f[i])
	i += 1
print(ans)


(n, m) = map(int, input().split())
a = [int(i) for i in input().split()]
a = sorted(a)
s = 0
mi = 2000
if n == m:
	print(a[m - 1] - a[0])
else:
	for i in range(m - n + 1):
		s = a[i + n - 1] - a[i]
		if s < mi:
			mi = s
	print(mi)


(n, m) = map(int, input().split())
puzzles = list(map(int, input().split()))
puzzles.sort()
current = 0
minim = 10 ** 8
for i in range(n - 1, m):
	current = puzzles[i] - puzzles[i - n + 1]
	if minim > current:
		minim = current
print(minim)


(n, p) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
x = []
for i in range(len(l)):
	l[i:i + n]
	if len(l[i:i + n]) == n:
		a = max(l[i:i + n]) - min(l[i:i + n])
		x.append(a)
print(min(x))


(n, m) = map(int, input().split())
l = [int(i) for i in input().split()]
l.sort()
a = m - n
lst = [l[n + i - 1] - l[i] for i in range(a + 1)]
print(min(lst))


(n, m) = list(map(int, input().split()))
lis = sorted(list(map(int, input().split())))
ans = []
if n == m:
	print(max(lis) - min(lis))
else:
	for i in range(m - n + 1):
		ans.append(lis[i + n - 1] - lis[i])
	print(min(ans))


(n, m) = [int(x) for x in input().split()]
nums = [int(x) for x in input().split()]
nums.sort()
for x in range(0, m - n + 1):
	if x == 0:
		Min = nums[x + n - 1] - nums[x]
		continue
	temp = nums[x + n - 1] - nums[x]
	if temp < Min:
		Min = temp
print(Min)


(n, m) = [int(x) for x in input().split()]
f = [int(x) for x in input().split()]
f.sort()
min_diff = 10000
for i in range(m - n + 1):
	diff = f[i + n - 1] - f[i]
	if diff < min_diff:
		min_diff = diff
print(min_diff)


(n, m) = [int(x) for x in input().split()]
numbers = [int(x) for x in input().split()]
numbers = sorted(numbers)
min = 1000
for i in range(0, m - n + 1):
	if numbers[i - 1 + n] - numbers[i] < min:
		min = numbers[i + n - 1] - numbers[i]
print(min)


(n, m) = map(int, input().split(' '))
p = input().split(' ')
puzzle = []
for i in p:
	puzzle.append(int(i))
puzzle.sort()
minimum = puzzle[m - 1] - puzzle[0]
i = 0
j = n - 1
for i in range(m - n + 1):
	if puzzle[i + n - 1] - puzzle[i] < minimum:
		minimum = puzzle[i + n - 1] - puzzle[i]
print(minimum)


(n, m) = [int(x) for x in input().split()]
puzzles = [int(x) for x in input().split()]
puzzles.sort(reverse=True)
difference = puzzles[0] - puzzles[n - 1]
for i in range(1, m - n + 1):
	difference = min(difference, puzzles[i] - puzzles[i + n - 1])
print(difference)


(n, m) = map(int, input().split(' '))
puzzles = list(map(int, input().split(' ')))
for i in range(m):
	minimum = i
	for j in range(i, m - 1):
		if puzzles[minimum] > puzzles[j + 1]:
			minimum = j + 1
	temp = puzzles[i]
	puzzles[i] = puzzles[minimum]
	puzzles[minimum] = temp
minValue = puzzles[n - 1] - puzzles[0]
for i in range(1, m - n + 1):
	if minValue > puzzles[i + n - 1] - puzzles[i]:
		minValue = puzzles[i + n - 1] - puzzles[i]
print(minValue)


(n, m) = map(int, input().split())
li = list(map(int, input().split()))
li = sorted(li)
b = 461656545
for k in range(m - n + 1):
	b = min(b, li[k + n - 1] - li[k])
print(b)


import bisect, math
(f, g) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
res = math.inf
for i in range(len(arr) - f + 1):
	tmp = arr[i:i + f]
	res = min(res, max(tmp) - min(tmp))
print(res)


(ew, er) = list(map(int, input().split()))
tr = list(map(int, input().split()))
tr.sort()
w = 1000
for j in range(er - ew + 1):
	yt = tr[j + ew - 1] - tr[j]
	if yt < w:
		w = yt
print(w)


import math
import os
import sys
import re
import itertools
import functools
import operator
(n, m) = map(int, input().split())
A = sorted(map(int, input().split()))
res = float('inf')
for i in range(n - 1, m):
	res = min(res, A[i] - A[i - n + 1])
print(res)


(n, m) = map(int, input().split())
p = [int(i) for i in input().split()]
min = float('inf')
p.sort()
for i in range(m - n + 1):
	p_slice = p[0 + i:n + i]
	if abs(p_slice[0] - p_slice[len(p_slice) - 1]) < min:
		min = abs(p_slice[0] - p_slice[len(p_slice) - 1])
print(min)


def main():
	(n, m) = map(int, input().split())
	f = list(map(int, input().split()))
	f.sort()
	mn = 1000000000.0
	for i in range(m - n + 1):
		mn = min(mn, f[i + n - 1] - f[i])
	print(mn)
main()


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


(a, b) = (int(x) for x in input().split())
l = list(map(int, input().split()))
l = sorted(l)
l1 = []
s = 0
for i in range(b - a + 1):
	l1.append(l[i + a - 1] - l[i])
print(min(l1))


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


def puzzles():
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	arr = list(map(int, input().split()))[:m]
	arr.sort()
	puzzle = []
	for i in range(len(arr)):
		temp = arr[i:i + n]
		if len(temp) == n:
			puzzle.append(temp)
		else:
			continue
	diff = []
	for j in range(len(puzzle)):
		k = puzzle[j][-1] - puzzle[j][0]
		diff.append(k)
	print(min(diff))
puzzles()


(n, m) = [int(s) for s in input().split()]
f = [int(s) for s in input().split()]
f.sort()
min_diff = 1001
for i in range(0, m - n + 1):
	min_diff = min(min_diff, f[i + n - 1] - f[i])
print(min_diff)


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
ans = 1000000000000000
i = 0
while i + n <= m:
	ans = min(ans, arr[i + n - 1] - arr[i])
	i += 1
print(ans)


(n, m) = map(int, input().split())
f = sorted(map(int, input().split()))
i = m + 1 - n
j = []
for t in range(0, i):
	e = max(f[t:n]) - min(f[t:n])
	j.append(int(e))
	n += 1
print(min(j))


(n, m) = map(int, input().split(' '))
f = list(map(int, input().split(' ')))
f = sorted(f)
res = 99999999
i = 0
j = n - 1
while j < m:
	res = min(res, f[j] - f[i])
	i += 1
	j += 1
print(res)


(n, m) = map(int, input().split())
ls = list(map(int, input().split()))
mid = []
out = []
ls.sort()
for i in range(n, len(ls) + 1):
	for j in range(i - n, i):
		mid.append(ls[j])
	out.append(mid[-1] - mid[0])
	mid = []
out.sort()
print(out[0])


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


(n, m) = list(map(int, input().split()))
s = sorted(list(map(int, input().split())))
wtf = 100000000000000000
for i in range(m - n + 1):
	wtf = min(wtf, max(s[i:i + n]) - min(s[i:i + n]))
print(wtf)


(a, b) = map(int, input().split())
n = list(map(int, input().split()))
n.sort()
min = None
for i in range(a - 1, b):
	ann = n[i] - n[i - a + 1]
	if min is None or ann < min:
		min = ann
print(min)


n = int(input().split(' ')[0])
sorted_list = sorted(list(map(int, input().split(' '))))
max_index = len(sorted_list) - n
least_difference = 10000000000
for i in range(0, max_index + 1):
	diff = sorted_list[i + n - 1] - sorted_list[i]
	if diff < least_difference:
		least_difference = diff
print(least_difference)


inp = input().split()
inp = list(map(int, inp))
n = inp[0]
m = inp[1]
jig = input().split()
jig = sorted(list(map(int, jig)))
dif = []
i = 0
while i + n != m + 1:
	list = jig[i:i + n]
	A = max(list)
	B = min(list)
	dif.append(A - B)
	i = i + 1
print(min(dif))


(a, b) = input().split()
a = int(a)
b = int(b)
c = [i for i in range(b)]
d = input().split()
for i in range(b):
	c[i] = int(d[i])
for i in range(b):
	for j in range(b - i - 1):
		if c[j] < c[j + 1]:
			x = c[j]
			c[j] = c[j + 1]
			c[j + 1] = x
dd = 1000
if b == a:
	dd = c[0] - c[b - 1]
for i in range(b - a + 1):
	rr = c[i] - c[i + a - 1]
	if rr < dd:
		dd = rr
print(dd)


from sys import stdin

def readInts():
	return map(int, stdin.readline().strip().split())

def solve(m, n, vs):
	min_diff = vs[m - 1] - vs[0]
	for ix_lo in range(1, n - m + 1):
		d = vs[ix_lo + m - 1] - vs[ix_lo]
		if d < min_diff:
			min_diff = d
	return min_diff

def run():
	(n, m) = readInts()
	vs = sorted(readInts())
	print(solve(n, m, vs))
run()


(n, m) = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
l.sort()
x = []
l1 = []
i = 0
while i <= len(l) - n:
	x = l[i:n + i]
	i += 1
	l1.append(x[-1] - x[0])
if len(l1) == 0:
	print('0')
else:
	print(min(l1))


children = int(input().split()[0])
a = [int(i) for i in input().split(' ')]
a.sort()
distances = []
for x in range(len(a) - (children - 1)):
	distances.append(a[x + (children - 1)] - a[x])
print(min(distances))


(student, puzzle) = [int(i) for i in input().split()]
puzzStor = [int(i) for i in input().split()]
puzzStor.sort()
diffGlobal = 999999
for i in range(0, len(puzzStor)):
	if i + (student - 1) == len(puzzStor):
		break
	else:
		diffGlobal = min(diffGlobal, puzzStor[i + student - 1] - puzzStor[i])
print(diffGlobal)


def puzzle(n, m, a):
	a.sort()
	mini = float('inf')
	for i in range(m - n + 1):
		if a[i + n - 1] - a[i] < mini:
			mini = a[i + n - 1] - a[i]
	return mini
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
print(puzzle(n, m, a))


def _m_check(stu, puzz, _list):
	_list = sorted(_list)
	best = 1000
	count = 0
	while puzz - stu >= count:
		best = min(best, _list[count + stu - 1] - _list[count])
		count += 1
	return best
(students, puzzles) = list(map(int, input().split()))
_list = list(map(int, input().split()))
print(_m_check(students, puzzles, _list))


from sys import stdin, stdout, exit as sys_ret
(f_input, f_print, f_flush) = (stdin.readline, stdout.write, stdout.flush)
(needed, amount) = map(int, f_input().split())
puzzle = sorted([int(_) for _ in f_input().split()])
minn = abs(puzzle[0] - puzzle[needed - 1])
for i in range(1, amount - needed + 1):
	if abs(puzzle[i] - puzzle[i + needed - 1]) < minn:
		minn = abs(puzzle[i] - puzzle[i + needed - 1])
f_print(str(minn))


(n, m) = [int(i) for i in input().split()]
f = sorted([int(i) for i in input().split()])
ans = 22120948120
for b in range(n - 1, m):
	a = b - n + 1
	ans = min(ans, f[b] - f[a])
print(ans)


(need, size) = list(map(int, input().split(' ')))
str = list(map(int, input().split(' ')))
str.sort()
min = 999999999
c = 0
for i in range(0, size - need + 1):
	c = str[i + need - 1] - str[i]
	if c < min:
		min = c
if min > c:
	min = c
print(min)


(a, b) = map(int, input().split())
lis = list(map(int, input().split()))
lis.sort()
l = []
for i in range(b - 1):
	lis[i] = lis[i + 1] - lis[i]
lis.pop()
temp = 0
for j in range(b - a + 1):
	for i in range(j, j + a - 1):
		temp = lis[i] + temp
	l.append(temp)
	temp = 0
print(min(l))


(n, m) = list(map(int, input().split()))
li = list(map(int, input().split()))
li.sort()
mn = 100000000
for i in range(len(li) - n + 1):
	mn = min(mn, li[i + n - 1] - li[i])
print(mn)


inp = input().split(' ')
n = int(inp[0])
m = int(inp[1])
inp = input().split(' ')
inp = [int(i) for i in inp]
puzzle = sorted(inp)
mp = 10 ** 8
i = 0
while i <= m:
	if i + n - 1 >= m:
		break
	sp = puzzle[i:i + n]
	k = sp[-1] - sp[0]
	if k < mp:
		mp = k
	i = i + 1
print(mp)


import math
(n, m) = list(map(int, input().rstrip().split()))
f = list(map(int, input().rstrip().split()))
f.sort()
dif = math.inf
for i in range(0, m - n + 1):
	dif = min(dif, f[i + n - 1] - f[i])
print(dif)


lines = [int(i) for i in str(input()).split()]
values = [int(i) for i in str(input()).split()]
values.sort()
ranges = []
for i in range(lines[1] - lines[0] + 1):
	ranges.append(values[i - 1 + lines[0]] - values[i])
print(min(ranges))


nm = list(input().split(' '))
students = int(nm[0])
presents = int(nm[1])
l = sorted(list(map(int, input().split(' '))))
M = []
m = []
for i in range(len(l) - students + 1):
	M = l[i:i + students]
	m.append(max(M) - min(M))
print(min(m))


a = [int(i) for i in input().split(' ')]
students = a[0]
puzzles = a[1]
a = [int(i) for i in input().split(' ')]
a.sort()
l = []
for i in range(0, puzzles - students + 1):
	l.append(a[i + students - 1] - a[i])
print(min(l))


(n, m) = map(int, input().split())
l = sorted(list(map(int, input().split())))
(i, j) = (0, 1000)
while i + n - 1 in range(m):
	if l[i + n - 1] - l[i] < j:
		j = l[i + n - 1] - l[i]
	i += 1
print(j)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 1000000000.0
for i in range(m - n + 1):
	x = abs(a[i] - a[i + n - 1])
	if x < ans:
		ans = x
print(ans)


(n, m) = [int(x) for x in input().split(' ')]
l = sorted([int(x) for x in input().split(' ')])
diff = l[n - 1] - l[0]
for i in range(m - n + 1):
	nd = l[n + i - 1] - l[i]
	diff = min(diff, nd)
print(diff)


def find_difference(n, m, numbers):
	numbers = sorted(numbers)
	diff = numbers[m - 1] - numbers[0]
	for i in range(m - n + 1):
		if numbers[i + n - 1] - numbers[i] < diff:
			diff = numbers[i + n - 1] - numbers[i]
	return diff
nm = input().split(' ')
n = int(nm[0])
m = int(nm[1])
numbers = input().split(' ')
newnumbers = []
for num in numbers:
	newnumbers.append(int(num))
print(find_difference(n, m, newnumbers))


(n, m) = map(int, input().split())
s = [int(i) for i in input().split()]
s.sort()
maxmin = max(s) - min(s)
for i in range(0, len(s) - n + 1):
	i_maxmin = max(s[i:i + n]) - min(s[i:i + n])
	if maxmin > i_maxmin:
		maxmin = i_maxmin
print(maxmin)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l = sorted(l)
k = 50000
for i in range(m - n + 1):
	d = l[n + i - 1] - l[i]
	if k > d:
		k = d
print(k)


def puz(n, m, l):
	l.sort()
	l1 = []
	for i in range(0, m - n + 1):
		l1.append(l[i + n - 1] - l[i])
	l1.sort()
	return l1[0]
(n, m) = map(int, input().split())
l = list(map(int, input().split()))
print(puz(n, m, l))


def puzzles():
	s = [int(x) for x in input().split()]
	(n, m) = (s[0], s[1])
	f = sorted([int(x) for x in input().split()])
	diff = f[n - 1] - f[0]
	for i in range(m - n + 1):
		if f[n + i - 1] - f[i] < diff:
			diff = f[n + i - 1] - f[i]
	print(diff)
puzzles()


(n, m) = map(int, input().split())
l = [int(n) for n in input().split()]
l.sort()
x = 0
s = int(l[n - 1]) - int(l[0])
r = m - n + 1
w = n - 1
for i in range(r):
	x = l[i + w] - l[i]
	if x < s:
		s = x
print(s)


inp = list(map(int, input().split()))
(k, m) = inp
arr = list(map(int, input().split()))
arr.sort()
mini = 9999999999999999999999
for i in range(len(arr) - k + 1):
	mini = min(arr[i + k - 1] - arr[i], mini)
print(mini)


func = lambda : map(int, input().split())
(n, m) = func()
puzzlist = sorted(func())
print(min((puzzlist[i + n - 1] - puzzlist[i] for i in range(m - n + 1))))


def comparison(pazzels, childrens, n):
	i = 0
	k = 0
	while i <= n - childrens:
		comparisons.append(pazzels[k] - pazzels[k + childrens - 1])
		i += 1
		k += 1
	print(min(comparisons))
comparisons = []
n = 2
things = [int(n) for n in input().split()]
childrens = things[0]
n = things[1]
pazzels = [int(n) for n in input().split()]
pazzels.sort()
pazzels.reverse()
comparison(pazzels, childrens, n)


userEntry = list(map(int, input().split()))
students = userEntry[0]
puzzels = userEntry[1]
puzzelsList = list(map(int, input().split()))
puzzelsList.sort()
times = puzzels - students + 1
smallerDif = -1
for time in range(times):
	actualDif = abs(puzzelsList[time] - puzzelsList[time + (students - 1)])
	if actualDif < smallerDif or smallerDif == -1:
		smallerDif = actualDif
print(smallerDif)


import math
(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
m_n = math.inf
for i in range(m - n + 1):
	m_n = min(m_n, l[i + n - 1] - l[i])
	if m_n == 0:
		break
print(m_n)


students_puzzles = []
students_puzzles.append(input().split())
puzzles_students = []
for i in students_puzzles[0]:
	puzzles_students.append(int(i))
students = puzzles_students[0]
puzzles = puzzles_students[1]
pieces = []
pieces.append(input().split())
new_pieces = []
for j in pieces[0]:
	new_pieces.append(int(j))
new_pieces.sort()
differences = []
for i in range(0, puzzles - students + 1):
	selected = []
	for j in range(students):
		selected.append(new_pieces[i + j])
	max = 0
	min = selected[0]
	diff = 0
	for k in selected:
		if k > max:
			max = k
		else:
			continue
	for p in selected:
		if p < min:
			min = p
		else:
			continue
	diff = max - min
	differences.append(diff)
min_diff = differences[0]
for i in differences:
	if i < min_diff:
		min_diff = i
	else:
		continue
print(min_diff)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
i = 0
max = l[-1]
b = n - 1
while b < m:
	d = l[b] - l[i]
	if d < max:
		max = d
	b = b + 1
	i = i + 1
print(max)


(n, m) = map(int, input().split())
arr = sorted(map(int, input().split()))
for i in range(m - n + 1):
	if i == 0:
		res = arr[n - 1] - arr[0]
	else:
		res = min(res, arr[i + n - 1] - arr[i])
print(res)


(n, m) = map(int, input().split())
lst = [int(i) for i in input().split()]
lst.sort()
i = 0
mn = 10000
while i + n - 1 < m:
	d = lst[i + n - 1] - lst[i]
	if d < mn:
		mn = d
	i = i + 1
print(mn)


from sys import stdin, stdout
(numberOfStudents, numberOfPuzzles) = map(int, stdin.readline().rstrip().split())
puzzles = list(map(int, stdin.readline().rstrip().split()))
puzzles.sort()
minimum = 1000
iMin = 0
iMax = 0
for i in range(numberOfPuzzles - numberOfStudents + 1):
	if minimum > puzzles[i + numberOfStudents - 1] - puzzles[i]:
		minimum = puzzles[i + numberOfStudents - 1] - puzzles[i]
		iMin = i
		iMax = i + numberOfStudents - 1
print(minimum)


(n, m) = [int(x) for x in input().split()]
puzzles = [int(x) for x in input().split()]
puzzles = sorted(puzzles)
min = 1000
for i in range(m - n + 1):
	if puzzles[i + n - 1] - puzzles[i] < min:
		min = puzzles[i + n - 1] - puzzles[i]
print(min)


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


(n, m) = (int(i) for i in input().split())
shop = [int(i) for i in input().split()]
shop.sort()
i = 0
x = 1000
while i <= m - n:
	if shop[i + n - 1] - shop[i] < x:
		x = shop[i + n - 1] - shop[i]
	i += 1
print(x)


(m, n) = [int(x) for x in input().split()]
array = [int(x) for x in input().split()]
list.sort(array)
length = len(array)
min = 10000
for i in range(m - 1, n):
	s = array[i] - array[i - m + 1]
	if s <= min:
		min = s
print(min)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
a[::-1]
diff = 100000
for i in range(0, m - n + 1):
	diff = min(diff, abs(a[i + n - 1] - a[i]))
print(str(diff))


from itertools import combinations
(n, m) = list(map(int, input().split()))
l = sorted(list(map(int, input().split())))
mini = 100000000000
for i in range(m - n + 1):
	mini = min(mini, l[i + n - 1] - l[i])
print(mini)


import sys
students_puzzles = input().split()
puzzles = input().split()
puzzles = [int(x) for x in puzzles]
puzzles.sort()
table = len(puzzles) * [sys.maxsize]
n_student = int(students_puzzles[0])
for i in range(0, len(puzzles)):
	if i + n_student > len(puzzles):
		break
	table[i] = puzzles[i + n_student - 1] - puzzles[i]
print(min(table))


(n, m) = input().split()
lines = input().split()
n = int(n)
m = int(m)
ans_list = []
for num in range(m):
	lines[num] = int(lines[num])
lines.sort()
for i in range(m - n + 1):
	line = lines[i:i + n]
	ans = abs(int(max(line)) - int(min(line)))
	ans_list.append(ans)
ans_last = min(ans_list)
print(ans_last)


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
f.sort()
min = 21978249058398292439052437690
for i in range(m - n + 1):
	if f[i + n - 1] - f[i] <= min:
		min = f[i + n - 1] - f[i]
print(min)


nm = input().split(' ')
n = int(nm[0])
m = int(nm[1])
puzzleSize = input().split(' ')
for i in range(len(puzzleSize)):
	puzzleSize[i] = int(puzzleSize[i])
puzzleSize.sort()
a = 0

def takeMin(curVal, prevVal=None):
	if prevVal == None:
		return curVal
	elif prevVal <= curVal:
		return prevVal
	else:
		return curVal
smallestDifference = 1001
while a + n <= len(puzzleSize):
	b = a + n - 1
	if a == 0:
		smallestDifference = takeMin(puzzleSize[b] - puzzleSize[a])
	else:
		smallestDifference = takeMin(puzzleSize[b] - puzzleSize[a], smallestDifference)
	a += 1
print(smallestDifference)


(k, n) = [int(x) for x in input().split()]
a = sorted([int(x) for x in input().split()])
m = float('inf')
for i in range(n - k + 1):
	if m > a[i + k - 1] - a[i]:
		m = a[i + k - 1] - a[i]
print(m)


t = list(map(int, input().split()))
k = t[0]
n = t[1]
a = list(map(int, input().split()))
a.sort()
i = 0
v = 0
max = -1
while i < n:
	try:
		if max == -1:
			max = a[i + k - 1] - a[i]
		elif a[i + k - 1] - a[i] < max:
			max = a[i + k - 1] - a[i]
	except Exception as e:
		break
	i += 1
if max == -1:
	print(0)
	v = 1
if v != 1:
	print(max)


a = [int(x) for x in input().split()]
puzzle = sorted([int(x) for x in input().split()])
people = puzzle[a[0] - 1] - puzzle[0]
if len(puzzle) - a[0] > 0:
	for i in range(len(puzzle) - a[0] + 1):
		people = min(puzzle[a[0] - 1 + i] - puzzle[i], people)
	print(people)
else:
	print(puzzle[a[0] - 1] - puzzle[0])


(i, s) = (input, str.split)
n = int(s(i())[0]) - 1
d = sorted(list(map(int, s(i()))))
print(min((d[j + n] - d[j] for j in range(len(d) - n))))


s1 = input().split()
n = int(s1[0])
m = int(s1[1])
min = 1000
s2 = input().split()
f = [0 for i in range(0, m)]
for i in range(0, m):
	f[i] = int(s2[i])
f = sorted(f)
for i in range(0, m - (n - 1)):
	if f[i + n - 1] - f[i] < min:
		min = f[i + n - 1] - f[i]
print(min)


(n, m) = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr.sort()
Ans = 1000
for j in range(m - n + 1):
	MaxNo = arr[j + n - 1]
	MinNo = arr[j]
	Diff = MaxNo - MinNo
	if Diff <= Ans:
		Ans = Diff
print(Ans)


(m, n) = map(int, input().split())
arr = list(map(int, input().split()))
count = []
arr.sort()
for i in range(len(arr) - m + 1):
	d = arr[i + m - 1] - arr[i]
	if d >= 0:
		count.append(d)
print(min(count))


(x, y) = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = []
for i in range(y - x + 1):
	b.append(a[i + x - 1] - a[i])
print(min(b))


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


(n, m) = map(int, input().split())
L = list(map(int, input().split()))
L.sort()
i = 0
c = 10 ** 18
while i < m and i + n - 1 < m:
	A = L[i + n - 1]
	B = L[i]
	c = min(c, A - B)
	i = i + 1
print(c)


(n, m) = (int(x) for x in input().split())
ips = [int(x) for x in input().split()]
ips.sort(reverse=True)
mx = 2000
for i in range(0, m - n + 1):
	x = ips[i:i + n]
	cal = x[0] - x[n - 1]
	if cal < mx:
		mx = cal
print(mx)


(student, puzzles) = map(int, input().split())
input_list = list(map(int, input().split()))
input_list.sort()
ans = input_list[student - 1] - input_list[0]
for i in range(puzzles - student + 1):
	if input_list[i + (student - 1)] - input_list[i] < ans:
		ans = input_list[i + (student - 1)] - input_list[i]
print(ans)


i = [int(i) for i in input().split(' ')]
n = i[0]
m = i[-1]
pieces = [int(i) for i in input().split(' ')]

def BubbleSort(l):
	lastEl = len(l) - 1
	for passNo in range(lastEl, 0, -1):
		for idx in range(lastEl):
			if l[idx] > l[idx + 1]:
				(l[idx], l[idx + 1]) = (l[idx + 1], l[idx])
	return l
srtPc = BubbleSort(pieces)
last = len(srtPc) - 1
curr = 0
diffList = []
while curr + n - 1 <= last:
	diff = srtPc[curr + n - 1] - srtPc[curr]
	diffList.append(diff)
	curr += 1
print(min(diffList))


(a, b) = map(int, input().split())
q = sorted(list(map(int, input().split())))
li = []
for i in range(b - a + 1):
	c = q[i + a - 1] - q[i]
	li.append(c)
print(min(li))


(n, m) = tuple(map(int, input().split()))
puzzles = sorted(map(int, input().split()))
min_diff = diff = puzzles[n - 1] - puzzles[0]
for i in range(1, m - n + 1):
	diff = puzzles[n + i - 1] - puzzles[i]
	min_diff = min(min_diff, diff)
print(min_diff)


(a, b) = input().split()
(a, b) = (int(a), int(b))
c = []
c = input().split()
c = list(map(int, c))
c = sorted(c)
diff = []
for i in range(0, len(c) - a + 1, 1):
	diff.append(c[i + a - 1] - c[i])
print(min(diff))


n = list(map(int, input().split()))
m = list(map(int, input().split()))
m.sort()
a = list()
for i in range(n[1] - n[0] + 1):
	a.append(max(m[i:i + n[0]]) - min(m[i:i + n[0]]))
if n[1] == n[0] and min(m) == max(m):
	print('0')
else:
	print(min(a))


(n, m) = [int(s) for s in input().split()]
sum = 1001
a = sorted([int(s) for s in input().split()])
for i in range(0, m - n + 1):
	sum = min(sum, a[i + n - 1] - a[i])
print(sum)


(a, b) = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]
m = sorted(t)
d = m[a - 1] - m[0]
for i in range(0, b - a + 1):
	D = m[a - 1 + i] - m[i]
	d = min(d, D)
print(d)


while True:
	try:
		(n, m) = [int(e) for e in input().split()]
		x = [int(e) for e in input().split()]
	except:
		break
	x = sorted(x)
	num = []
	for i in range(m - n + 1):
		p = x[i:i + n]
		num.append(max(p) - min(p))
	print(min(num))


def fun(n, m, li):
	li = sorted(li)
	x = []
	for i in range(m - n + 1):
		x.append(li[n - 1 + i] - li[i])
	print(min(x))
(n, m) = list(map(lambda x: int(x), input().split()))
li = list(map(lambda x: int(x), input().split()))
fun(n, m, li)


(n, m) = input().split()
l = input().split()
for i in range(0, len(l)):
	l[i] = int(l[i])
l.sort()
l1 = []
for i in range(0, int(m) - int(n) + 1):
	l1.append(l[i + int(n) - 1] - l[i])
l1.sort()
print(l1[0])


import sys
(n, m) = map(int, input().split())
res = []
a = sorted([int(x) for x in input().split()])
if m == n:
	print(max(a) - min(a))
	sys.exit(0)
for i in range(m - n + 1):
	res.append(max(a[i:i + n]) - min(a[i:i + n]))
print(min(res))


from sys import stdin

def doblen(lst, n, m):
	min_val = float('inf')
	for i in range(m):
		new_j = i + (n - 1)
		if new_j >= m:
			break
		min_val = min(min_val, lst[new_j] - lst[i])
	return min_val

def main():
	global lst, n, res
	(n, m) = map(int, stdin.readline().split())
	lst = list(map(int, stdin.readline().split()))
	lst.sort()
	print(doblen(lst, n, m))
main()


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
f.sort()
a = 1001
for i in range(m - n + 1):
	e = max(f[i:i + n])
	d = min(f[i:i + n])
	c = e - d
	a = min(c, a)
print(a)


(s, p) = map(int, input().split())
arr = sorted(list(map(int, input().split())))
print(min((arr[i + s - 1] - arr[i] for i in range(p - s + 1))))


nums = list(map(int, input().split()))
(n, m) = (nums[0], nums[1])
puzzles = list(map(int, input().split()))
puzzles.sort()
minDiff = puzzles[n - 1] - puzzles[0]
for i in range(m - n + 1):
	minDiff = min(puzzles[i + n - 1] - puzzles[i], minDiff)
print(minDiff)


(n, m) = map(int, input().split())
n = n - 1
li = list(map(int, input().split()))
ans = float('inf')
li.sort()
for i in range(len(li) - n):
	if li[i + n] - li[i] < ans:
		ans = li[i + n] - li[i]
print(ans)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
res = 100000000
for i in range(len(l)):
	x = l[i:n + i]
	if len(x) == n:
		ans = max(x) - min(x)
		res = min(ans, res)
print(res)


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


(num, m) = [int(x) for x in input().split()]
choice = [int(x) for x in input().split()]
choice.sort()
b = choice[num - 1] - choice[0]
for i in range(len(choice) - num + 1):
	if choice[i + num - 1] - choice[i] < b:
		b = choice[i + num - 1] - choice[i]
print(b)


(n, m) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
best = 1000000000000
for i in range(0, m - n + 1):
	best = min(best, a[i + n - 1] - a[i])
print(best)


(n, m) = map(int, input().split())
lst = [int(s) for s in input().split()]
lst = sorted(lst)
res = 10000
i = 0
while i <= m - n:
	if res > lst[i + n - 1] - lst[i]:
		res = lst[i + n - 1] - lst[i]
	i += 1
print(res)


(n, k) = map(int, input().split())
array = list(map(int, input().split()))
array.sort()
a = []
b = []
for i in range(k - n + 1):
	a = []
	for j in range(n):
		a.append(array[i + j])
	b.append(max(a) - min(a))
print(min(b))


(n, m) = map(int, input().split())
x = input().split()
for i in range(m):
	x[i] = int(x[i])
x.sort()
r = 10000
for i in range(m - n + 1):
	y = i
	z = y + n - 1
	if x[z] - x[y] < r:
		r = x[z] - x[y]
print(r)


[n, m] = [int(i) for i in input().split(' ')]
a = [int(j) for j in input().split(' ')]
a.sort()
dif = 1000
for i in range(m - n + 1):
	if a[i + n - 1] - a[i] < dif:
		dif = a[i + n - 1] - a[i]
print(dif)


(n, m) = list(map(lambda x: int(x), input().split()))
a = sorted(list(map(lambda x: int(x), input().split())))
print(min((a[i + n - 1] - a[i] for i in range(m - n + 1))))


(m, n) = map(int, input().split())
mas = sorted([int(i) for i in input().split()])
minimal = 999999999
new_mas = []
if m < n:
	for i in range(n - m + 1):
		new_mas = []
		for j in range(i, i + m):
			new_mas.append(mas[j])
		raz = max(new_mas) - min(new_mas)
		if minimal > raz:
			minimal = raz
	print(minimal)
else:
	print(max(mas) - min(mas))


(n, m) = map(int, input().split())
values = map(int, input().split())
newvalues = sorted(values)
start = 0
last = n - 1
minimum = newvalues[last] - newvalues[start]
while last < m:
	temp1 = newvalues[last] - newvalues[start]
	last += 1
	start += 1
	minimum = min(minimum, temp1)
print(minimum)


import sys
import math
import os
(n, m) = map(int, input().split())
data = list(map(int, input().split()))
data.sort()
delta = 1000
for i in range(m - n + 1):
	if data[i + n - 1] - data[i] < delta:
		delta = data[i + n - 1] - data[i]
print(delta)


(n, m) = map(int, input().split())
puzzles = list(map(int, input().split()))
puzzles.sort()
difference = 10000
for i in range(m - n + 1):
	if puzzles[i + n - 1] - puzzles[i] < difference:
		difference = puzzles[i + n - 1] - puzzles[i]
print(difference)


import math
(n, m) = map(int, input().split())
arr = [int(i) for i in input().split()]
arr.sort()
least = arr[n - 1] - arr[0]
for i in range(1, m - n + 1):
	if arr[i + n - 1] - arr[i] < least:
		least = arr[i + n - 1] - arr[i]
print(least)


first = input().split()
n = int(first[0])
m = int(first[1])
ins = input().split()
pieces = [int(i) for i in ins]
pieces.sort()
groups = [pieces[j:j + n] for j in range(m - n + 1)]
diffs = []
for i in groups:
	diffs.append(max(i) - min(i))
print(min(diffs))


(n, k) = map(int, input().split())
lis = [int(x) for x in input().split()]
lis.sort()
min1 = 100000
for i in range(0, k - n + 1):
	x = lis[i + n - 1] - lis[i]
	if min1 > x:
		min1 = x
print(min1)


t = list(map(int, input().split()))
k = list(map(int, input().split()))
k.sort()
for i in range(len(k)):
	if i == 0:
		min = k[i + t[0] - 1] - k[i]
	else:
		m = k[i + t[0] - 1] - k[i]
		if m < min:
			min = m
	if i + t[0] - 1 == len(k) - 1:
		break
print(min)


import sys
import random
from math import log2, log, ceil
input = sys.stdin.readline

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a > 0:
		return gcd(b % a, a)
	return b

def primefs(n):
	if n == 1:
		return 1
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	while x != link[x]:
		x = link[x]
	return x

def union(x, y, size, link):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().split()))
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
(k, n) = int_array()
puzz = sorted(int_array())
ans = INF
for i in range(n - k + 1):
	ans = min(ans, puzz[i + k - 1] - puzz[i])
print(ans)


parametrs = list(map(int, input().split()))
puzzles = list(map(int, input().split()))
m = parametrs[1]
n = parametrs[0]

def partition(arr, low, high):
	i = low - 1
	pivot = arr[high]
	for j in range(low, high):
		if arr[j] <= pivot:
			i = i + 1
			(arr[i], arr[j]) = (arr[j], arr[i])
	(arr[i + 1], arr[high]) = (arr[high], arr[i + 1])
	return i + 1

def quick_sort(arr, low, high):
	if low < high:
		p_i = partition(arr, low, high)
		quick_sort(arr, low, p_i - 1)
		quick_sort(arr, p_i + 1, high)
quick_sort(puzzles, 0, m - 1)
min_diff = 1000
step = 0
while n + step <= m:
	lr = step
	rh = step + n
	array_select = puzzles[lr:rh]
	diff = max(array_select) - min(array_select)
	if min_diff >= diff:
		min_diff = diff
	step += 1
print(min_diff)


(n, m) = map(int, input().split())
li = [int(i) for i in input().split()]
li.sort()
if n == m:
	print(li[-1] - li[0])
else:
	c = 9999
	for i in range(0, m - n + 1):
		a = li[i:i + n]
		c = min(c, a[-1] - a[0])
	print(c)


import math
from sys import stdin, stdout, maxsize
(n, m) = map(int, stdin.readline().split())
l = [int(x) for x in stdin.readline().split()]
l.sort()
mini = maxsize
for i in range(0, m - n + 1):
	if mini > l[i + n - 1] - l[i]:
		mini = l[i + n - 1] - l[i]
print(mini)


(n, k) = map(int, input().split())
li = list(map(int, input().split()))
li.sort()
a = 2 ** 30
d = 0
for i in range(k - n + 1):
	d = abs(li[i] - li[i + n - 1])
	if a > d:
		a = d
print(a)


(n, m) = map(int, input().split())
li = sorted(list(map(int, input().split())))
j = m - 1
i = m - n
l = []
while i >= 0:
	x = li[j] - li[i]
	l.append(x)
	i -= 1
	j -= 1
print(min(l))


import math
(numberOfStudents, numberOfPuzzles) = [int(ip) for ip in input().split(' ')]
puzzleSizes = [int(ip) for ip in input().split(' ')]
sortedPuzzleSizes = sorted(puzzleSizes, reverse=True)
minDiff = sortedPuzzleSizes[0] - sortedPuzzleSizes[numberOfStudents - 1]
for i in range(0, numberOfPuzzles - numberOfStudents + 1):
	if minDiff > sortedPuzzleSizes[i] - sortedPuzzleSizes[i + numberOfStudents - 1]:
		minDiff = sortedPuzzleSizes[i] - sortedPuzzleSizes[i + numberOfStudents - 1]
	else:
		continue
print(minDiff)


from math import *
from copy import *
from string import *
from random import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
import math
(n, m) = map(int, input().split(' '))
mini = 10000000
l = list(map(int, input().split(' ')))
l.sort()
for i in range(m - n + 1):
	if abs(l[i] - l[i + n - 1]) < mini:
		mini = abs(l[i] - l[i + n - 1])
print(mini)


from sys import stdin as inp
from sys import stdout as out
from sys import maxsize as max
(n, m) = list(map(int, inp.readline().strip().split()))
a = list(map(int, inp.readline().strip().split()))
a.sort()
ans = max
(i, j) = (m - n, m - 1)
while i >= 0:
	ans = min(ans, a[j] - a[i])
	i -= 1
	j -= 1
out.write(str(ans))


(n, m) = map(int, input().split())
l = sorted(list(map(int, input().split())))
(d, l1) = (0, [])
for i in range(m - n + 1):
	d = l[n + i - 1] - l[i]
	l1.append(d)
print(min(l1))


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


(n, m) = map(int, input().split(' '))
x = [int(a) for a in input().split(' ')]
x.sort()
i = 0
j = n - 1
res = x[j] - x[i]
while j < len(x) - 1:
	i += 1
	j += 1
	if x[j] - x[i] < res:
		res = x[j] - x[i]
print(res)


(n, m) = map(int, input().split())
c = sorted(list(map(int, input().split())))
w = []
for i in range(m - n + 1):
	t = c[i:i + n]
	w.append(max(t) - min(t))
print(min(w))


gegeven = input().split(' ')
numbersinput = input()
numbers = list(map(int, numbersinput.split(' ')))
KleinsteVerschil = 2000
numbers.sort()
for i in range(0, int(gegeven[1]) - int(gegeven[0]) + 1):
	verschil = int(numbers[int(gegeven[0]) + i - 1]) - int(numbers[i])
	if verschil < KleinsteVerschil:
		KleinsteVerschil = verschil
print(KleinsteVerschil)


(n, m) = map(int, input().split())
array = list(map(int, input().split()))
array.sort()
low = array[m - 1] - array[0]
for i in range(0, m - n + 1):
	if abs(array[i + n - 1] - array[i]) < low:
		low = abs(array[i + n - 1] - array[i])
print(low)


(n, m) = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
list.sort(arr)
minDiff = arr[n - 1] - arr[0]
minI = 0
for i in range(1, m - n + 1):
	diff = arr[i + n - 1] - arr[i]
	if diff < minDiff:
		minDiff = diff
		minI = i
print(minDiff)


(n, m) = map(int, input().split(' '))
lis = list(map(int, input().split(' ')))
lis.sort()
sum = 0
max = lis[n - 1] - lis[0]
for i in range(m - n + 1):
	for j in range(i, n + i - 1):
		sum = sum + lis[j + 1] - lis[j]
	if max > sum:
		max = sum
	sum = 0
print(max)


(m, n) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
res = 99999
for i in range(len(a) - m + 1):
	res = min([res, a[i + m - 1] - a[i]])
print(res)


def sol(a):
	return max(a) - min(a)
solution = 1001
(n, m) = map(int, input().split())
a = sorted([int(i) for i in input().split()])
for i in range(m - n + 1):
	if solution > sol(a[i:n + i]):
		solution = sol(a[i:n + i])
print(solution)


n = input().split()
l = map(int, input().split())
f = []
for i in l:
	f.append(i)
f.sort()
t = int(f[len(f) - 1]) - int(f[0])
for i in range(len(f) - int(n[0]) + 1):
	if t > f[i + int(n[0]) - 1] - f[i]:
		t = f[i + int(n[0]) - 1] - f[i]
print(t)


(n, m) = map(int, input().split())
a = [int(i) for i in input().split()]
array = [9999]
for i in a:
	index = 0
	while array[index] < i:
		index += 1
	array.insert(index, i)
MIN = 9999
array = array[:-1]
for i in range(m - n + 1):
	MIN = min(MIN, array[i + n - 1] - array[i])
print(MIN)


import math
(puzzles_needed, puzzles_available) = [int(x) for x in input().split()]
puzzles = sorted([int(x) for x in input().split()])
puzzles_differences = []
for i in range(0, puzzles_available - puzzles_needed + 1):
	diff = puzzles[puzzles_needed + i - 1] - puzzles[i]
	puzzles_differences.append(diff)
print(min(puzzles_differences))


(count_of_children, count_of_pazl) = map(int, input().split())
data = list(map(int, input().split()))
data.sort()
minimum = data[:count_of_children]
for i in range(count_of_pazl - count_of_children + 1):
	min_test = data[i:i + count_of_children]
	if max(minimum) - min(minimum) > max(min_test) - min(min_test):
		minimum = min_test
print(max(minimum) - min(minimum))


(n, m) = [int(x) for x in input().split()]
ms = [int(x) for x in input().split()]
ms.sort()
ans = 10 ** 10
for i in range(m - n + 1):
	s = ms[i + n - 1] - ms[i]
	ans = min(ans, s)
print(ans)


(student, psize) = [int(x) for x in input().split(' ')]
puzzless = [int(x) for x in input().split(' ')]
puzzless.sort()
best = puzzless[-1]
i = 0
while i <= psize - student:
	best = min(best, puzzless[i + student - 1] - puzzless[i])
	i += 1
print(best)


(n, m) = [int(i) for i in input().split()]
line = [int(j) for j in input().split()]
line.sort()
minimum = line[m - 1] - line[0]
for k in range(m - n + 1):
	minimum = min(minimum, line[k + n - 1] - line[k])
print(minimum)


(n, m) = tuple(map(int, input().strip().split(' ')))
puz = list(map(int, input().strip().split(' ')))
puz.sort()
ans = puz[n - 1] - puz[0]
for j in range(0, m - n + 1):
	val = puz[j + n - 1] - puz[j]
	if val < ans:
		ans = val
print(ans)


(n, m) = [int(i) for i in input().split(' ')]
f = sorted([int(i) for i in input().split(' ')])
r = f[len(f) - 1]
for i in range(m - n + 1):
	r = r if r < f[i + n - 1] - f[i] else f[i + n - 1] - f[i]
print(r)


(n, m) = map(int, input().split())
peices = sorted(map(int, list(input().split())))
best = peices[n - 1] - peices[0]
for x in range(0, m - n + 1):
	best = min(best, peices[x + n - 1] - peices[x])
print(best)


(k, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
mi = 1000000007
if m == k:
	print(l[m - 1] - l[0])
else:
	for i in range(0, m - k + 1):
		mi = min(mi, l[i + k - 1] - l[i])
	print(mi)


from sys import stdin, stdout
inp = stdin.readline
out = stdout.write
(n, m) = map(int, inp().strip().split())
a = list(map(int, inp().strip().split()))
a.sort()
d = []
for i in range(m - n + 1):
	d.append(a[i + n - 1] - a[i])
out(str(min(d)))


(n, m) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.sort()
min = 99999999999999
for i in range(0, m - n + 1):
	if a[i + n - 1] - a[i] < min:
		min = a[i + n - 1] - a[i]
print(min)


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


(n, b) = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
c.sort()
m = max(c)
for i in range(b - n + 1):
	if c[i + n - 1] - c[i] < m:
		m = c[i + n - 1] - c[i]
print(m)


(n, m) = map(int, input().split())
puzzles = list(sorted(map(int, input().split())))
counter = 100000
tmp = 0
i = 0
while n - 1 + i < m:
	tmp = puzzles[n - 1 + i] - puzzles[i]
	counter = min(tmp, counter)
	i += 1
print(counter)


nm = list(map(int, input().split()))
n = nm[0]
m = nm[1]
puzlist = list(map(int, input().split()))
puzlist.sort()
ans = 10000
for i in range(m - n + 1):
	ans = min(ans, puzlist[i + n - 1] - puzlist[i])
print(ans)


lis_2 = []
(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
a = l[0]
for i in range(m - n + 1):
	lis = []
	lis.append(a)
	for j in range(i + 1, i + n):
		lis.append(l[j])
	lis_2.append(max(lis) - min(lis))
	lis.clear()
	a = l[i + 1]
print(min(lis_2))


arr = input().split(' ')
n = int(arr[0])
m = int(arr[1])
arr = input().split(' ')
puzzles = sorted([int(a) for a in arr])
best = -1
for i in range(len(puzzles) - n + 1):
	smallest = puzzles[i]
	largest = puzzles[i + n - 1]
	if best == -1 or largest - smallest < best:
		best = largest - smallest
print(best)


(n, m) = map(int, input().split())
a = [int(j) for j in input().split()]
a.sort()
ans = 999999999
for i in range(0, m - n + 1):
	min1 = a[i + (n - 1)] - a[i]
	ans = min(ans, min1)
print(ans)


nums = input('')
pazzl = input(' ')
pazzl = pazzl.split(' ')
nums = nums.split(' ')
(n, m) = (int(nums[0]), int(nums[1]))
int_pazzl = []
for i in range(0, m):
	int_pazzl.append(int(pazzl[i]))
sort_pazzl = sorted(int_pazzl)
min_result = 2000000000
for i in range(0, m - n + 1):
	result = sort_pazzl[i + n - 1] - sort_pazzl[i]
	min_result = min(min_result, result)
print(min_result)


nm = input()
inp = input()
(n, m) = nm.split()
n = int(n)
m = int(m)
arr = inp.split()
narr = list()
for i in arr:
	narr.append(int(i))
narr.sort()
minimum = narr[-1]
for i in range(m - n + 1):
	if narr[i + n - 1] - narr[i] < minimum:
		minimum = narr[i + n - 1] - narr[i]
print(minimum)


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
f.sort()
first = 0
last = n - 1
min = 10000
while last < m:
	s = f[last] - f[first]
	if min > s:
		min = s
	first = first + 1
	last = last + 1
print(min)


from sys import stdin, stdout
(n, m) = [int(x) for x in stdin.readline().split()]
listo = [int(x) for x in stdin.readline().split()]
listo.sort()
cou = listo[int(n) - 1] - listo[0]
c = 0
while n < m + 1:
	ou = listo[int(n) - 1] - listo[c]
	if ou < cou:
		cou = ou
	else:
		pass
	n += 1
	c += 1
print(cou)


(n, m) = map(int, input().split())
n -= 1
f = sorted(map(int, input().split()))
res = float('inf')
i = 0
l = len(f)
while i + n < l:
	res = min(res, f[i + n] - f[i])
	i += 1
print(res)


import math
(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
arr = sorted(arr)
minn = math.inf
for i in range(m - n + 1):
	a = arr[i:i + n]
	minn = min(minn, max(a) - min(a))
print(minn)


(a, b) = map(int, input().split())
c = list(map(int, input().strip().split()))
c.sort()
mini = []
i = 0
while i + a - 1 < len(c):
	mini.append(c[i + a - 1] - c[i])
	i += 1
print(min(mini))


(n, m) = map(int, input().split())
a = [int(x) for x in input().split()]
a.sort()
minn = 99999999
for i in range(len(a) - n + 1):
	if a[i + n - 1] - a[i] < minn:
		minn = a[i + n - 1] - a[i]
print(minn)


(x, y) = input().split()
x = int(x)
y = int(y)
a = input().split()
for i in range(0, y):
	a[i] = int(a[i])
a = sorted(a)
l = 0
first = 0
scand = 0
for j in range(0, y - x + 1):
	if a[j] == 1:
		a[j] = a[j] - 1
	if l <= 0:
		scand = a[j + (x - 1)] - a[j]
	first = a[j + (x - 1)] - a[j]
	if first < scand:
		scand = first
	l = l + 1
print(scand)


(a, b) = map(int, input().split())
s = sorted(list(map(int, input().split())))
r = set()
if b - a > 0:
	for i in range(b - a + 1):
		x = s[i + a - 1] - s[i]
		r.add(x)
else:
	r.add(s[-1] - s[0])
print(min(r))


(n, m) = input().split()
(n, m) = [int(n), int(m)]
buzzles = [int(x) for x in input().split()]
buzzles = sorted(buzzles)
min_list = []
for i in range(0, m - n + 1):
	min_list.append(buzzles[i + n - 1] - buzzles[i])
print(min(min_list))


i = lambda : map(int, input().split())
(n, m) = i()
f = sorted(list(i()))
print(min((f[i + n - 1] - f[i] for i in range(m - n + 1))) if m > n else f[m - 1] - f[0])


(n, m) = map(int, input().split())
ls = input().split()
for i in range(0, m):
	ls[i] = int(ls[i])
ls.sort()
mn = 1000000000.0
(lo, hi) = (0, n - 1)
while True:
	if hi >= m:
		break
	mn = min(mn, ls[hi] - ls[lo])
	lo += 1
	hi += 1
print(mn)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
ans = []
for i in range(m - n + 1):
	x = l[i:i + n]
	diff = x[len(x) - 1] - x[0]
	ans.append(diff)
print(min(ans))


lines = []
while True:
	try:
		lines.append(input())
	except EOFError:
		break
puzzles = lines[1].split(' ')
line_1 = lines[0].split(' ')
students = line_1[0]
num_puzzles = line_1[1]
puzzles = list(map(int, puzzles))
puzzles.sort()
all_diff = []
for i in range(0, int(num_puzzles)):
	if int(students) - 1 + i < int(num_puzzles):
		diff = puzzles[int(students) - 1 + i] - puzzles[i]
		all_diff.append(diff)
	else:
		break
all_diff.sort()
print(all_diff[0])


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


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


a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
n = a[0]
m = a[1]
b.sort()
diff = list([])
for i in range(m):
	c = list([])
	e = list([])
	c.append(b)
	d = [abs(b[i] - x) for x in b]
	c.append(d)
	X = c[0]
	Y = c[1]
	X = [x for (y, x) in sorted(zip(Y, X))]
	c[0] = X
	c[1].sort()
	for j in range(n):
		e.append(c[0][j])
	maximum = max(e)
	minimum = min(e)
	diff.append(maximum - minimum)
diff.sort()
print(diff[0])


(n, m) = map(int, input().split())
puzzles = sorted(map(int, input().split()))
print(min([e - s for (s, e) in zip(puzzles, puzzles[n - 1:])]))


(n, m) = (int(i) for i in input().split(' '))
p = [int(i) for i in input().split(' ')]
p.sort(reverse=True)
ans = 9999
for i in range(m - n + 1):
	ans = min(p[i] - p[i + n - 1], ans)
print(ans)


data = input().split()
pupil = int(data[0])
puzzles = int(data[1])
fragments = input().split()
for i in range(0, puzzles):
	fragments[i] = int(fragments[i])
for i in range(1, puzzles):
	for j in range(1, puzzles):
		if fragments[j] < fragments[j - 1]:
			el = fragments[j]
			fragments[j] = fragments[j - 1]
			fragments[j - 1] = el
start_min_index = 0
start_max_index = pupil - 1
difference_idex = fragments[pupil - 1] - fragments[0]
while start_max_index <= puzzles - 1:
	min_val = fragments[start_min_index]
	max_val = fragments[start_max_index]
	result = max_val - min_val
	if result < difference_idex:
		difference_idex = result
	start_min_index = start_min_index + 1
	start_max_index = start_max_index + 1
print(difference_idex)


(a, b) = map(int, input().split())
x = input().split()
arr = []
for i in x:
	arr.append(int(i))
arr.sort()
temp = 9999999
for i in range(b - a + 1):
	temp = min(temp, arr[a + i - 1] - arr[i])
print(temp)


import sys
(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
s = 0
e = n
diff = sys.maxsize
for i in range(m - n + 1):
	mn = min(arr[s + i:e + i])
	mx = max(arr[s + i:e + i])
	if mx - mn < diff:
		diff = mx - mn
print(diff)


(n, m) = [int(x) for x in input().split()]
a = sorted([int(x) for x in input().split()])
res = 100000
for i in range(m - n + 1):
	res = min(res, a[i + n - 1] - a[i])
print(res)


line = input()
line = line.split()
n = int(line[0])
m = int(line[1])
line = input()
line = line.split()
for i in range(0, m):
	line[i] = int(line[i])
line.sort()
dif = 10000
for i in range(0, m - n + 1):
	if line[i + n - 1] - line[i] < dif:
		dif = line[i + n - 1] - line[i]
print(dif)


a = [int(i) for i in input().split()]
pieces = sorted([int(i) for i in input().split()], reverse=True)
c = 0
d = 0
mindif = []
dif = []
while c < a[1] - 1:
	dif.append(pieces[c] - pieces[c + 1])
	c += 1
while d + a[0] <= a[1]:
	mindif.append(sum(dif[d:d + a[0] - 1]))
	d += 1
print(min(mindif))


(N, M) = list(map(int, input().strip().split()))
L = list(map(int, input().strip().split()))
L.sort()
minimum = L[-1]
for i in range(M - N + 1):
	K = L[i:i + N]
	S = K[-1] - K[0]
	if S < minimum:
		minimum = S
print(minimum)


(n, m) = map(int, input().split())
mini = 3000
f = [int(x) for x in input().split()]
for i in range(0, m - 1):
	for j in range(1, m):
		if f[j] < f[j - 1]:
			f[j] += f[j - 1]
			f[j - 1] = f[j] - f[j - 1]
			f[j] -= f[j - 1]
for i in range(n - 1, m):
	if f[i] - f[i - n + 1] < mini:
		mini = f[i] - f[i - n + 1]
print(str(mini))


(n, m) = input().split(' ')
n = int(n)
m = int(m)
quants = list(map(int, input().split(' ')))[:m]
quants.sort(reverse=False)
least = quants[n - 1] - quants[0]
for i in range(m - n + 1):
	if quants[i + n - 1] - quants[i] < least:
		least = quants[i + n - 1] - quants[i]
print(least)


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


(n, m) = [int(x) for x in input().split(' ')]
puzzles = sorted([int(x) for x in input().split(' ')])
min_result = 1000
for x in range(0, m - n + 1):
	result = puzzles[x + n - 1] - puzzles[x]
	if result < min_result:
		min_result = result
print(min_result)


(n, m) = [int(x) for x in input().split()]
nums = [int(x1) for x1 in input().split()]
nums.sort()
maxDiff = max(nums) - min(nums)
for i in range(m - n + 1):
	min1 = min(nums[i:n + i])
	max1 = max(nums[i:i + n])
	if max1 - min1 < maxDiff:
		maxDiff = max1 - min1
print(maxDiff)


(n, m) = map(int, input().split())
array = list(map(int, input().split()))
array.sort()
ans = 1000001
for i in range(m - n + 1):
	ans = min(array[i + n - 1] - array[i], ans)
print(ans)


info = input()
ss = int(info.split()[0])
ps = int(info.split()[1])
puzzles = input()
Puzzles = [int(i) for i in puzzles.split()]
Puzzles.sort(reverse=True)
rang = []
for i in range(len(Puzzles) - ss + 1):
	rang.append(Puzzles[i] - Puzzles[i + ss - 1])
print(min(rang))


s = []
(m, n) = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
if n - m != 0:
	for z in range(n - m + 1):
		a = p[z + m - 1] - p[z]
		s.append(a)
	s.sort()
	print(s[0])
if n - m == 0:
	print(p[-1] - p[0])


s = list(map(int, input().split()))
p = list(map(int, input().split()))
p.sort()
check = []
least = []
for i in range(0, s[1] - s[0] + 1):
	for j in range(i, i + s[0]):
		ele = p[j]
		check.append(ele)
		check.sort()
	maximum = max(check)
	minimum = min(check)
	ele = maximum - minimum
	least.append(ele)
	check = []
least_maximum = min(least)
print(least_maximum)


import sys
a = sys.stdin.readline()
list = a.split()
n = int(list[0])
m = int(list[1])
a = sys.stdin.readline()
mylist = a.split()
mylist = [int(X) for X in mylist]
mylist.sort()
min = mylist[m - 1] - mylist[0]
for i in range(0, m - n + 1):
	if mylist[i + n - 1] - mylist[i] < min:
		min = mylist[i + n - 1] - mylist[i]
print(min)


(n, m) = map(int, input().split())
f = [int(i) for i in input().split()]
f.sort()
dif = 1000
for i in range(m - n + 1):
	dif = min(f[i + n - 1] - f[i], dif)
print(dif)


(n, m) = [int(x) for x in input().split()]
list1 = [int(x) for x in input().split()]
list1.sort()
key1 = sum(list1)
if m < n:
	for j in range(m - 1):
		key = list1[j + 1] - list1[j]
		key1 = min(key1, key)
else:
	for i in range(m + 1 - n):
		key = list1[i + n - 1] - list1[i]
		key1 = min(key1, key)
print(key1)


import sys
my_file = sys.stdin
line = [int(i) for i in my_file.readline().strip('\n').split()]
(n, m) = (line[0], line[1])
f = [int(i) for i in my_file.readline().split()]
f.sort()
min = f[n - 1] - f[0]
for i in range(m):
	try:
		if f[n - 1 + i] - f[i] < min:
			min = f[n - 1 + i] - f[i]
	except:
		pass
print(min)


(n, m) = str(input()).split(' ')
n = int(n)
m = int(m)
temp_list = str(input()).split(' ')
temp_list = [int(it) for it in temp_list]
temp_list.sort()
tar_list = list()
for i in range(m - (n - 1)):
	tar_list.append(temp_list[i + (n - 1)] - temp_list[i])
print(min(tar_list))


n = [int(i) for i in input().split()]
data = [int(i) for i in input().split()]
ans = 2000
data.sort()
for i in range(n[1]):
	if i + n[0] <= n[1]:
		ans = min([ans, data[i + n[0] - 1] - data[i]])
print(str(ans))


(n, m) = tuple(map(int, input().split()))
f = list(map(int, input().split()))
f.sort()
i = 0

def get_diff(i):
	return f[n - 1 + i] - f[i]
res = get_diff(i)
while n + i < m:
	i += 1
	if res > get_diff(i):
		res = get_diff(i)
print(res)


(n, m) = input().split()
n = int(n)
m = int(m)
l = [int(x) for x in input().split()]
best = 1001
l = sorted(l)
for i in range(m - n + 1):
	best = min(best, l[i + n - 1] - l[i])
print(best)


(s, p) = map(int, input().split())
size = [int(i) for i in input().split()]
size.sort()
diff = []
for i in range(len(size) - s + 1):
	diff.append(size[i + s - 1] - size[i])
diff.sort()
print(diff[0])


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


(n, m) = map(int, input().split())
f = [int(x) for x in input().split()]
f.sort()
x = []
if n == m:
	print(max(f) - min(f))
else:
	for i in range(m - n + 1):
		x.append(abs(f[i] - f[i + n - 1]))
	print(min(x))


[n, m] = [int(x) for x in input().split(' ')]
puzzles = sorted([int(x) for x in input().split(' ')])
minPossible = None
for i in range(n - 1, m):
	if minPossible is not None:
		minPossible = min(minPossible, puzzles[i] - puzzles[i - (n - 1)])
	else:
		minPossible = puzzles[i] - puzzles[i - (n - 1)]
print(minPossible)


(n, m) = map(int, input().split())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
f = []
for i in range(m - n + 1):
	ai = a[i] - a[-(m - n + 1) + i]
	f.append(ai)
f.sort()
print(f[0])


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


def solve(n, m, arr):
	mindiff = None
	diff = 0
	for i in range(0, m - n + 1):
		diff = arr[i + n - 1] - arr[i]
		if mindiff is None or mindiff >= diff:
			mindiff = diff
	return mindiff
(n, m) = map(int, input().split(' '))
arr = sorted(list(map(int, input().split(' '))))
print(solve(n, m, arr))


(n, m) = input().split()
pu = sorted(list(map(int, input().split())))
pu.append(0)
z = []
for x in range(max(1, int(m) - int(n) + 1)):
	z.append(pu[x + int(n) - 1] - pu[x])
print(min(z))


(m, n) = map(int, input().split())
l = [int(i) for i in input().split()]
l.sort()
d = 1001
for t in range(n - m + 1):
	c = l[t + m - 1] - l[t]
	if c < d:
		d = c
print(d)


def main():
	(n, m) = list(map(int, input().split()))
	lst = list(map(int, input().split()))
	lst.sort()
	minn = 9999999
	start = 0
	end = n - 1
	for i in range(n - 1, m):
		diff = lst[end] - lst[start]
		if diff < minn:
			minn = diff
		start += 1
		end += 1
	print(minn)
t = 1
while t != 0:
	main()
	t -= 1


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


def puzzle(n, l):
	least = l[n - 1] - l[0]
	for i in range(1, len(l) - n + 1):
		if l[i + n - 1] - l[i] < least:
			least = l[i + n - 1] - l[i]
	return least
(n, m) = map(int, input().split(' '))
l = list(map(int, input().split(' ')))
print(puzzle(n, sorted(l)))


k = 999999999999999999999999999999999999
(n, m) = list(map(int, input().split()))
puzzle = list(map(int, input().split()))
puzzle.sort()
t = n - 1
for i in range(t, len(puzzle)):
	if puzzle[i] - puzzle[i - t] < k:
		k = puzzle[i] - puzzle[i - t]
print(k)


(n, m) = (4, 6)
k = [10, 12, 10, 7, 5, 22]
(n, m) = list(map(int, input().split()))
k = list(map(int, input().split()))
k = sorted(k)
min_diff = k[n - 1] - k[0]
for i in range(len(k) - n + 1):
	diff = k[i + n - 1] - k[i]
	min_diff = min(diff, min_diff)
print(min_diff)


import sys
(children, pieces) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
diff = sys.maxsize
for i in range(pieces - children + 1):
	diff = min(diff, arr[i + children - 1] - arr[i])
print(diff)


input_str = [int(x) for x in input().split()]
pieces = [int(x) for x in input().split()]
students = input_str[0]
pieces.sort()
diff = 1000
for i in range(len(pieces) - (students - 1)):
	if pieces[i + students - 1] - pieces[i] < diff:
		diff = pieces[i + students - 1] - pieces[i]
print(str(diff))


(d, ma) = (0, 9999)
(a, b) = map(int, input().split())
c = input().split()
c = [int(c[i]) for i in range(b)]
c.sort()
for i in range(b - a + 1):
	d = c[a + i - 1] - c[0 + i]
	ma = min(d, ma)
print(ma)


(k, n) = map(int, input().split(' '))
l = list(map(int, input().split(' ')))
t = sorted(l)
u = []
i = 0
while i <= n - k:
	u.append(max(t[i:i + k]) - min(t[i:i + k]))
	i = i + 1
if len(u) > 0:
	print(min(u))
else:
	print(0)


import math
import sys

def puzzle(n, m, arr):
	l = []
	diff = math.inf
	i = 0
	for i in range(n):
		l.append(max(arr))
		arr.remove(max(arr))
	if len(arr) == 0:
		return max(l) - min(l)
	else:
		while True:
			min1 = min(l)
			max1 = max(l)
			if diff > max1 - min1:
				diff = max1 - min1
			if len(arr) == 0:
				break
			l.remove(max1)
			l.append(max(arr))
			arr.remove(max(arr))
			i -= 1
	return diff
input = sys.stdin.read()
(n, m, *arr) = list(map(int, input.split()))
print(puzzle(n, m, arr))


import sys

def main():
	stdin = sys.stdin.read().split('\n')
	(n, m) = tuple(map(int, stdin[0].split()))
	f = list(map(int, stdin[1].split()))
	f.sort()
	print(min((f[n - 1 + i] - f[i] for i in range(m - n + 1))))
main()


def f(n, k, a):
	a.sort()
	ans = c = 10000000
	if n == k:
		return a[n - 1] - a[0]
	for i in range(0, n - k + 1):
		b = a[k + i - 1] - a[i]
		ans = min(b, c)
		c = ans
	return ans
(k, n) = input().split(' ')
(k, n) = (int(k), int(n))
a = list(map(int, input().split(' ')))
print(f(n, k, a))


(students, size) = map(int, input().split())
puzzles = list(map(int, input().split()))
puzzles.sort()
left_ptr = 0
right_ptr = students - 1
min_diff = puzzles[right_ptr] - puzzles[left_ptr]
while right_ptr < size - 1:
	left_ptr += 1
	right_ptr += 1
	min_diff = min(min_diff, puzzles[right_ptr] - puzzles[left_ptr])
print(min_diff)


p = input().split()
x = int(p[0])
y = int(p[1])
l = input().split()
l = list(map(int, l))
ll = []
l.sort()
n = l.__len__()
for i in range(y - x + 1):
	ll.append(l[x + i - 1] - l[i])
print(min(ll))


(n, m) = map(int, input().split())
pieces = list(map(int, input().split()))
pieces = sorted(pieces, reverse=True)
_m = float('inf')
temp = float('inf')
for i in range(len(pieces) - (n - 1)):
	temp = pieces[i] - pieces[i + n - 1]
	if temp < _m:
		_m = temp
print(_m)


def min_difference(fs, n):
	best = None
	i = 0
	l = len(fs)
	fs.sort()
	while i + n - 1 < l:
		d = fs[i + n - 1] - fs[i]
		if best == None or d < best:
			best = d
		i += 1
	return best
(n, m) = map(int, input().split())
fs = list(map(int, input().split()))
print(min_difference(fs, n))


def solve():
	(n, m) = [int(x) for x in input().split()]
	pieces = [int(x) for x in input().split()]
	pieces.sort()
	best = 1000 * m
	for i in range(n - 1, m):
		best = min(best, pieces[i] - pieces[i - (n - 1)])
	print(best)
	return
solve()


(n, m) = map(int, input().strip().split())
l = list(map(int, input().strip().split()))
l.sort()
fl = []
for i in range(m - n + 1):
	ans = l[len(l) - 1] - l[len(l) - n]
	fl.append(ans)
	l.remove(l[len(l) - 1])
print(min(fl))


(n, k) = map(int, input().rstrip().split(' '))
l1 = list(map(int, input().rstrip().split(' ')))
l1.sort()
if n == k:
	print(l1[-1] - l1[0])
else:
	min_d = 999999
	for i in range(k - n + 1):
		m = min(l1[i:i + n])
		ma = max(l1[i:i + n])
		z = ma - m
		if z < min_d:
			min_d = z
	print(min_d)


import bisect
(n, m) = [int(_) for _ in input().strip().split()]
arr = [int(_) for _ in input().strip().split()]
s = []
for i in arr:
	bisect.insort_left(s, i)
p = n - 1
ans = None
for i in range(m - n + 1):
	for j in range(i + p, m):
		diff = s[j] - s[i]
		if ans == None:
			ans = diff
		elif diff < ans:
			ans = diff
if ans:
	print(ans)
else:
	print(0)


from sys import stdin
entrada = [int(x) for x in stdin.read().split()]
n = entrada.pop(0)
m = entrada.pop(0)
entrada.sort()
min = entrada[n - 1] - entrada[0]
for i in range(m - n + 1):
	dif = entrada[i + n - 1] - entrada[i]
	if dif < min:
		min = dif
print(min)


(n, k) = map(int, input().split())
w = list(map(int, input().split()))
w.sort()
minimum = 10000000
for i in range(0, len(w) - n + 1):
	total = max(w[i:i + n]) - min(w[i:i + n])
	if total < minimum:
		minimum = total
print(minimum)


(n, m) = map(int, input().split())
values = list(map(int, input().split()))
values.sort()
minvalue = 100000000
if m != n:
	for i in range(0, len(values) - n + 1):
		minvalue = min(minvalue, values[i + n - 1] - values[i])
else:
	minvalue = values[n - 1] - values[0]
print(minvalue)


(n, m) = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
a.sort()
m1 = []
if n != m:
	for i in range(m - n + 1):
		k = a[i + n - 1] - a[i]
		m1.append(k)
	print(min(m1))
else:
	print(a[n - 1] - a[0])


(n, m) = map(int, input().split())
pieces = list(map(int, input().rstrip().rsplit()))
pieces.sort()
sub_lists = []
for i in range(m - n + 1):
	x = pieces[i:i + n]
	sub_lists.append(x)
differences = []
for i in sub_lists:
	y = max(i) - min(i)
	differences.append(y)
print(min(differences))


(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
min = 99999
for i in range(m - n + 1):
	d = a[i + n - 1] - a[i]
	if d < min:
		min = d
print(min)


def find_smallest_diff(n, pieces):
	ps = sorted(pieces)
	m = 99999999
	for i in range(n - 1, len(pieces)):
		d = abs(ps[i] - ps[i - n + 1])
		if d < m:
			m = d
	return m
(n, _) = input().split(' ')
pieces = list(map(int, input().split(' ')))
print(find_smallest_diff(int(n), pieces))


ed = input().split()
a = int(ed[0])
b = int(ed[1])
edd = input().split()
d = []
for i in range(b):
	c = int(edd[i])
	d.append(c)
e = sorted(d)
f = []
for j in range(a - 1, len(e)):
	g = abs(e[j - (a - 1)] - e[j])
	f.append(g)
if len(f) == 0:
	print(0)
else:
	print(min(f))


(n, m) = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr.sort()
ans = arr[n - 1] - arr[0]
for i in range(1, m):
	if i + n - 1 > m - 1:
		break
	ans = min(ans, arr[i + n - 1] - arr[i])
print(ans)


(n, m) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
a.sort()
e = max(a)
ans = 1000000
for i in range(m - n + 1):
	e = min(a[i + n - 1] - a[i], e)
print(e)


(n, m) = map(int, input().split(' '))
l = list(map(int, input().split(' ')))
l = sorted(l)
l1 = []
for i in range(m - n + 1):
	a = l[i:i + n]
	b = max(a) - min(a)
	l1.append(b)
print(min(l1))


S = sorted
M = lambda : map(int, input().split())
(n, m) = M()
p = S(list(M()))
ans = 999999999
for i in range(0, m):
	try:
		if p[i + n - 1] - p[i] < ans:
			ans = p[i + n - 1] - p[i]
	except:
		pass
print(ans)


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


(x, y) = [int(a) for a in input().split()]
m = list(map(int, input().split()))[:y]
m.sort()
b = []
for i in range(0, y - (x - 1)):
	ar = []
	for j in range(i, i + x):
		ar.append(m[j])
	k = max(ar) - min(ar)
	b.append(k)
print(min(b))


(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
ans = 10000
for i in range(m - n + 1):
	d = a[i:i + n]
	delta = max(d) - min(d)
	if delta < ans:
		ans = delta
print(ans)


(n, m) = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
p = sorted(p, reverse=True)
if m >= n:
	minj = 0
	min = 9999999
	for j in range(m - n + 1):
		if p[j] - p[j + n - 1] < min:
			minj = j
			min = p[j] - p[j + n - 1]
	print(min)
else:
	print(p[0] - p[-1])


(n, m) = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
a.sort()
min = 9293252525
for i in range(m - n + 1):
	if a[i + n - 1] - a[i] < min:
		min = a[i + n - 1] - a[i]
print(min)


import sys
inf = float('inf')
(mod, MOD) = (1000000007, 998244353)

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(n, m) = get_ints()
Arr = get_array()
Arr.sort()
i = 0
j = n - 1
mini = 10 ** 9 + 7
while j < m:
	if Arr[j] - Arr[i] < mini:
		mini = Arr[j] - Arr[i]
	j += 1
	i += 1
print(mini)


(a, b) = [int(x) for x in input().split()]
m = sorted([int(x) for x in input().split()])
s = m[a - 1] - m[0]
for i in range(b - a + 1):
	x = m[i + a - 1] - m[i]
	if x <= s:
		s = x
print(s)


inp = input().split()
ns = int(inp[0])
np = int(inp[1])
inp = input().split()
for a in range(0, np - 1):
	min = int(inp[a])
	i = a
	for b in range(a + 1, np):
		if int(inp[b]) < min:
			min = int(inp[b])
			i = b
	tmp = inp[a]
	inp[a] = str(min)
	inp[i] = tmp
min = int(inp[ns - 1]) - int(inp[0])
for a in range(ns, np):
	if int(inp[a]) - int(inp[a - ns + 1]) < min:
		min = int(inp[a]) - int(inp[a - ns + 1])
print(min)


(n, m) = map(int, input().split())
r = 1000
k = sorted(list(map(int, input().split())))
for i in range(m):
	p = k[i + n - 1] - k[i]
	if p <= r:
		r = p
	if i + n == m:
		print(r)
		break


(n, m) = map(int, input().split())
a = [int(x) for x in input().split()]
a.sort()
down = float('inf')
for i in range(m - n + 1):
	k = a[i + n - 1] - a[i]
	if k < down:
		down = k
print(down)


import math as mt
import sys as sy

class abc:

	def mkl(self):
		(n, m) = map(int, sy.stdin.readline().split())
		n -= 1
		l = list(map(int, sy.stdin.readline().split()))
		li = sorted(l)
		ber = float('inf')
		for i in range(m - n):
			di = li[i + n] - li[i]
			ber = min(di, ber)
		print(ber)
b = abc()
b.mkl()


def main():
	[n, m] = [int(i) for i in input('').split()]
	val_list = [int(i) for i in input('').split()]
	val_list.sort()
	val_list.reverse()
	min_val = 999999999999999999999
	for i in range(0, m - n + 1):
		if val_list[i:i + n][0] - val_list[i:i + n][-1] < min_val:
			min_val = val_list[i:i + n][0] - val_list[i:i + n][-1]
		else:
			pass
	print('%d' % min_val)
main()


import sys
(n, m) = map(int, sys.stdin.readline().split())
fis = list(map(int, sys.stdin.readline().split()))
fis.sort()
diff = -1
for i in range(m - n + 1):
	if diff < 0:
		diff = fis[i + n - 1] - fis[i]
	elif fis[i + n - 1] - fis[i] < diff:
		diff = fis[i + n - 1] - fis[i]
print(diff)


l = [int(k) for k in input().split(' ')]
(n, m) = (l[0], l[1])
f = [int(k) for k in input().split(' ')]
f.sort()
r = 10000
for i in range(m - n + 1):
	r = min(r, f[i + n - 1] - f[i])
print(r)


(n, m) = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
arr.sort()
min = 1000000000000000000000000000
for i in range(m - n + 1):
	if arr[n + i - 1] - arr[i] < min:
		min = arr[n + i - 1] - arr[i]
print(min)


l = input().split()
m = int(l[0])
n = int(l[1])
a = input().split()
a = [int(i) for i in a]
a.sort()
min = a[m - 1] - a[0]
for i in range(1, len(a) - m + 1):
	if a[i + m - 1] - a[i] < min:
		min = a[i + m - 1] - a[i]
print(min)


puzzles = input()
numbers = input()
puzzles = list(map(int, puzzles.split()))
numbers = list(map(int, numbers.split()))
teacherPuzzles = puzzles[0]
storePuzzles = puzzles[1]
numbers.sort()
i = 0
answer = -1
while i < len(numbers):
	number = numbers[i]
	if i + (teacherPuzzles - 1) < len(numbers):
		difference = numbers[i + (teacherPuzzles - 1)] - number
		if difference < answer or answer < 0:
			answer = difference
	else:
		break
	i += 1
print(answer)


(n, m) = map(int, input().split())
p = map(int, input().split())
p = sorted(p)
b = p[n - 1] - p[0]
if n == m:
	print(max(p) - min(p))
else:
	for i in range(m - n + 1):
		d = p[i + n - 1] - p[i]
		b = min(d, b)
	print(b)


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


(p, q) = map(int, input().split())
lst = list(map(int, input().split()))
min1 = sum(lst)
lst.sort()
for i in range(q - p + 1):
	if min1 > abs(min(lst[i:i + p]) - max(lst[i:i + p])):
		min1 = abs(min(lst[i:i + p]) - max(lst[i:i + p]))
print(min1)


(n, m) = map(int, input().split(' '))
p = sorted(list(map(int, input().split(' '))))
d = 1000
for i in range(m - n + 1):
	try:
		newp = p[i:i + n]
		if d > newp[-1] - newp[0]:
			d = newp[-1] - newp[0]
	except:
		pass
print(str(d))


(n, m) = [int(x) for x in input().split()]
something = sorted([int(x) for x in input().split()])
minimum = 10 ** 5
for i in range(0, m - n + 1):
	minimum = min(minimum, max(something[i:i + n]) - min(something[i:i + n]))
print(minimum)


num = input().split()
n = int(num[0])
m = int(num[1])
l = input().split()
for i in range(m):
	l[i] = int(l[i])
l.sort()
mini = l[m - 1]
for i in range(m - n + 1):
	diff = l[i + n - 1] - l[i]
	if diff < mini:
		mini = diff
print(mini)


tmp = input()
tmp = tmp.split()
(n, m) = (int(tmp[0]), int(tmp[1]))
a = input()
a = a.split()
a = [int(i) for i in a]
a.sort()
a = [a[i + n - 1] - a[i] for i in range(len(a) - n + 1)]
print(min(a))


x = input()
x = list(map(int, x.split()))
p = int(x[0])
q = int(x[1])
a = input()
n = list(map(int, a.split()))
n = sorted(n)
i = 0
diff = 0
ordif = 10000
while i <= q - p:
	diff = n[p + i - 1] - n[i]
	if diff < ordif:
		ordif = diff
	i = i + 1
print(ordif)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
p = len(l)
q = []
l.sort()
for i in range(p - n + 1):
	s = l[i:n + i]
	ma = max(s)
	mi = min(s)
	q.append(ma - mi)
print(min(q))


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


(n, k) = list(map(int, input().split()))
p = list(map(int, input().split()))
ol = []
p.sort()
x = 0
while x + n <= k:
	ol.append(p[x + n - 1] - p[x])
	x += 1
print(min(ol))


(n, m) = [int(x) for x in input().split()]
f = [int(x) for x in input().split()]
f.sort()
opt = 10000
for i in range(m - n + 1):
	(min_, max_) = (min(f[i:i + n]), max(f[i:i + n]))
	if max_ - min_ < opt:
		opt = max_ - min_
print(opt)


from collections import Counter
from sys import maxsize
(n, m) = map(int, input().split())
ls = list(map(int, input().split()))
ls.sort()
minn = maxsize
for i in range(m):
	for j in range(i, m):
		if len(ls[i:j + 1]) == n:
			a_min = min(ls[i:j + 1])
			a_max = max(ls[i:j + 1])
			op = a_max - a_min
			if op <= minn:
				minn = op
print(minn)


(n, m) = list(map(int, input().split()))
m_p = sorted(list(map(int, input().split())))
res = max(m_p) - min(m_p)
n -= 1
for i in range(len(m_p) - n):
	a = m_p[i + n] - m_p[i]
	if a < res:
		res = a
print(res)


(n, m) = map(int, input().split())
quant = list(map(int, input().split()))
quant.sort()
diff = float('inf')
for i in range(m - n + 1):
	frst = quant[i]
	lst = quant[i + n - 1]
	tdiff = lst - frst
	diff = min(diff, tdiff)
print(diff)


(n, puzzles) = [list(map(int, input().split())) for _ in range(2)]
minimum = False
puzzles.sort()
for i in range(0, len(puzzles) - n[0] + 1):
	distance = puzzles[i + n[0] - 1] - puzzles[i]
	if distance <= minimum or minimum is False:
		minimum = distance
if minimum is False:
	print(0)
else:
	print(minimum)


from itertools import combinations
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
mnn = 1000000000.0
for i in range(m - n + 1):
	fmx = max(a[i:i + n])
	fmn = min(a[i:i + n])
	fuck = fmx - fmn
	if fuck < mnn:
		mnn = fuck
print(mnn)


nums = input().split()
n = int(nums[0])
m = int(nums[1])
outs = []
line = list(map(int, input().split()))
line.sort()
for i in range(m - n + 1):
	outs.append(line[i + n - 1] - line[i])
Nmin = min(outs)
print(Nmin)


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


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
minDiff = float('inf')
if n == m:
	minDiff = min(minDiff, abs(l[0] - l[n - 1]))
else:
	for i in range(m - n + 1):
		minDiff = min(minDiff, abs(l[i] - l[i + n - 1]))
print(minDiff)


(n, m) = list(map(int, input().split()))
lst = list(map(int, input().split()))
if n < m:
	lst.sort()
	mini = 10000000
	for i in range(0, m):
		if len(lst[i:i + n]) == n:
			sumi = lst[i:i + n][-1] - lst[i:i + n][0]
		if sumi < mini:
			mini = sumi
	print(mini)
else:
	print(max(lst) - min(lst))


(a, b) = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
c.sort()
k = 1001
for i in range(0, b - a + 1):
	k = min(k, c[i + a - 1] - c[i])
print(k)


nm = list(map(int, input().split(' ')))
coins = list(map(int, input().split(' ')))
coins.sort()
m = 999999999999
for i in range(nm[0] - 1, nm[1]):
	m = min(m, coins[i] - coins[i - nm[0] + 1])
print(m)


s = input().split()
t = input().split()
t = list(map(int, t))
t.sort()
S = []
for i in range(int(s[1]) - int(s[0]) + 1):
	a = t[i + int(s[0]) - 1] - t[i]
	S.append(a)
print(min(S))


in_n_m = input()
in_prices = input()
n = int(in_n_m.split()[0])
m = int(in_n_m.split()[1])
prices = sorted([int(x) for x in in_prices.split()])
minDiff = 9223372036854775807
for i in range(m - (n - 1)):
	diff = prices[i + (n - 1)] - prices[i]
	if diff < minDiff:
		minDiff = diff
print(minDiff)


(n, m) = [int(x) for x in input().split()]
f = [int(x) for x in input().split()]
f.sort()
res = float('inf')
for i in range(0, m - n + 1):
	res = min(res, f[i + n - 1] - f[i])
print(res)


s = input()
s = s.split()
n = s[0]
m = s[1]
n = int(n)
m = int(m)
l = input()
l = l.split()
i = 0
a = []
while i < m:
	g = int(l[i])
	a.append(g)
	i = i + 1
a.sort()
min = 0
min = a[n - 1] - a[0]
i = n
j = 1
diff = 0
while i < m:
	diff = a[i] - a[j]
	if diff < min:
		min = diff
	i = i + 1
	j = j + 1
print(min)


import sys
puzzleInput = input().split(' ')
noStudents = int(puzzleInput[0])
noPuzzles = int(puzzleInput[1])
puzzles = sorted([int(x) for x in input().split(' ')])
noWindows = noPuzzles - noStudents + 1
minNum = sys.maxsize
for i in range(noWindows):
	window = puzzles[i:i + noStudents]
	delta = max(window) - min(window)
	if delta < minNum:
		minNum = delta
print(minNum)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
mm = 10000
for j in range(m - n + 1):
	mm = min(mm, a[j + n - 1] - a[j])
print(mm)


(n, o) = list(map(int, input().split()))
s = list(map(int, input().split()))
s.sort()
dif = 10000000000000
for i in range(o - n + 1):
	dif = min(dif, -s[i] + s[i + n - 1])
print(dif)


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
f.sort()
best = 10000000
for i in range(m - n + 1):
	if f[i + n - 1] - f[i] < best:
		best = f[i + n - 1] - f[i]
print(best)


def main():
	s = list(input().split(' '))
	n = int(s[0])
	m = int(s[1])
	space = []
	f = []
	f1 = list(input().split(' '))
	for i1 in f1:
		f.append(int(i1))
	f.sort()
	i = 0
	while i <= m - 1 and n <= m:
		ww = f[i:n]
		maxi = int(max(ww))
		mini = int(min(ww))
		space.append(maxi - mini)
		i += 1
		n += 1
		ww.clear()
	print(min(space))
main()


data = list(map(int, input().split(' ')))
n = data[0]
m = data[1]
a = list(map(int, input().split(' ')))
a = sorted(a)
difference = float('inf')
for value in range(m - (n - 1)):
	if a[value + (n - 1)] - a[value] < difference:
		difference = a[value + (n - 1)] - a[value]
print(difference)


(n, m) = input().strip().split()
(n, m) = (int(n), int(m))
p = [int(i) for i in input().strip().split()]
p.sort()
q = p[:n]
diff = q[n - 1] - q[0]
for i in range(n, m):
	q.remove(q[0])
	q.append(p[i])
	diff2 = q[n - 1] - q[0]
	if diff2 < diff:
		diff = diff2
print(diff)


n = list(map(int, input().split()))[:2]
ps = list(map(int, input().split()))[:n[1]]
ps.sort()
vs = []
dif = 99999
for i in range(0, len(ps) - n[0] + 1):
	ls = n[0]
	vs = []
	for j in range(i, i + n[0]):
		vs.append(ps[j])
	vs.sort()
	diff = vs[n[0] - 1] - vs[0]
	if diff < dif:
		dif = diff
print(dif)


(n, m) = input().split(' ')
s = [int(i) for i in input().split(' ')]
dif = max(s) - min(s)
i = 0
while i < len(s):
	j = i + 1
	while j != len(s):
		if s[i] > s[j]:
			(s[i], s[j]) = (s[j], s[i])
		j += 1
	i += 1
i = 0
while i < len(s) - int(n) + 1:
	temp = s[i:i + int(n)]
	if temp[-1] - temp[0] < dif:
		dif = temp[-1] - temp[0]
	i += 1
print(dif)


(n, m) = map(int, input().split())
pieces = sorted(list(map(int, input().split())))
a = 0
minimum = []
while a <= m - n:
	x = int(pieces[a + n - 1] - pieces[a])
	minimum.append(x)
	a += 1
print(min(minimum))


import math
(n, m) = [int(x) for x in input().split(' ')]
ms = sorted([int(x) for x in input().split(' ')])
b = math.inf
for i in range(0, m - n + 1):
	d = min(b, ms[i + n - 1] - ms[i])
	if d < b:
		b = d
if m - n == 0:
	print(max(ms) - min(ms))
else:
	print(b)


import os
import re
import sys
import math
from io import BytesIO, IOBase

def main():
	(n, m) = [int(x) for x in sys.stdin.readline().split()]
	a = [int(x) for x in sys.stdin.readline().split()]
	a.sort()
	ans = 0
	i = 0
	sum_min = 99999999999999999999999999999999999
	while i <= m - n:
		j = i
		sum_diff = 0
		to = i + n - 2
		while j <= to:
			sum_diff = sum_diff + abs(a[j] - a[j + 1])
			j += 1
		if sum_diff < sum_min:
			ans = abs(max(a[i:i + n]) - min(a[i:i + n]))
			sum_min = sum_diff
		i += 1
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
main()


import array as arr
min = arr.array('i', [])
(n, m) = input('').split()
n = int(n)
m = int(m)
numlist = list(map(int, input('').strip().split()))[:m]
numlist.sort()
for i in range(m - n + 1):
	min.append(numlist[i + n - 1] - numlist[i])
min_index = 0
min_num = 100000
for i in range(m - n + 1):
	if min_num > min[i]:
		min_num = min[i]
		min_index = i
print(numlist[min_index + n - 1] - numlist[min_index])


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
c = float('inf')
l = zip(a, a[n - 1:])
for (i, j) in l:
	c = min(c, j - i)
print(c)


(a, b) = map(int, input().split())
c = sorted(map(int, input().split()))
mini = c[a - 1] - c[0]
for i in range(b - a + 1):
	a_b = c[i + a - 1] - c[i]
	mini = min(a_b, mini)
print(mini)


(n, m) = map(int, input().split())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
mn = 1000
for i in range(m - n + 1):
	mn = min(mn, a[i] - a[i + n - 1])
print(mn)


(n, m) = map(int, input().split())
f = sorted(list(map(int, input().split())))
solution = 1000
for i in range(0, m - n + 1):
	solution = min(solution, f[i + n - 1] - f[i])
print(solution)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)
(n, m) = LI()
students = LI()
diff = []
students.sort()
for i in range(0, m - (n - 1)):
	diff.append(students[i + n - 1] - students[i])
diff.sort()
print(min(diff))


(n, m) = input().split()
(n, m) = (int(n), int(m))
f = input().split()
f = list(map(lambda x: int(x), f))
f.sort()
cost = 1000000000
for i in range(m - n + 1):
	if cost > f[i + n - 1] - f[i]:
		cost = f[i + n - 1] - f[i]
print(cost)


import sys

def solve():
	(n, m) = map(int, input().split())
	f = list(map(int, input().split()))
	f.sort()
	res = 100000000
	for i in range(m - n + 1):
		res = min(res, f[i + n - 1] - f[i])
	print(res)
if sys.hexversion == 50594544:
	sys.stdin = open('test.txt')
solve()


def main():
	nm = input().split(' ')
	nm = [int(i) for i in nm]
	ints = input().split(' ')
	ints = [int(i) for i in ints]
	sortedints = sorted(ints)
	least_range = 100000
	for x in range(0, nm[1] - nm[0] + 1):
		if sortedints[nm[0] + x - 1] - sortedints[x] < least_range:
			least_range = sortedints[nm[0] + x - 1] - sortedints[x]
	print(least_range)
main()


(n, m) = map(int, input().split())
p = [int(x) for x in input().split()]
s = sorted(p)
i = 0
l = []
while i < int(m - n + 1):
	l.append(int(s[i + n - 1] - s[i]))
	i += 1
q = sorted(l)
print(q[0])


(n, m) = list(map(int, list(input().split())))
f = list(map(int, list(input().split())))
f.sort()
dif = []
for node1 in range(len(f) - n + 1):
	node2 = node1 + n - 1
	dif.append(f[node2] - f[node1])
print(min(dif))


(n, m) = map(int, input().split())
t = sorted([int(x) for x in input().split()])
mn = 1001
for i in range(m - n + 1):
	mn = min(mn, t[i + n - 1] - t[i])
print(mn)


(taken, total_sell) = [int(x) for x in input().split()]
another = [int(x) for x in input().split()]
another.sort()
express = []
for i in range(total_sell - taken + 1):
	result = another[i:i + taken]
	(minimum, maximum) = (min(result), max(result))
	final = abs(minimum - maximum)
	express.append(final)
print(min(express))


(n, m) = map(int, input().split())
mat = list(map(int, input().split()))
mat.sort()
i = 0
arr = []
while i + n - 1 < m:
	arr.append(mat[i + n - 1] - mat[i])
	i += 1
print(min(arr))


(n, m) = map(int, input().split())
minv = 1001
a = [int(i) for i in input().split()]
a.sort()
for i in range(m - n + 1):
	minv = min(minv, a[i + n - 1] - a[i])
print(minv)


(n, m) = map(int, input().split())
a = sorted(list(map(int, input().split())))
mi = float('inf')
for i in range(m - n + 1):
	mi = min(mi, abs(a[i] - a[i + n - 1]))
print(mi)


line = list(map(int, input().split(' ')))
n = line[0]
m = line[1]
numbers = list(map(int, input().split(' ')))
numbers.sort()
first = True
max = int('1000000')
for i in range(0, m - n + 1):
	if first:
		first = False
		max = numbers[i + n - 1] - numbers[i]
	elif max > numbers[i + n - 1] - numbers[i]:
		max = numbers[i + n - 1] - numbers[i]
print(max)


(n, m) = map(int, input().rstrip().split())
pieces = list(map(int, input().rstrip().split()))
p = sorted(pieces)
mindiff = 9999999
for i in range(m - n + 1):
	diff = p[i + (n - 1)] - p[i]
	mindiff = min(mindiff, diff)
print(mindiff)


(n, m) = [int(j) for j in input().split()]
a = [int(j) for j in input().split()]
a = sorted(a)
least = a[n - 1] - a[0]
for i in range(m - n + 1):
	least = min(a[i + n - 1] - a[i], least)
print(least)


def puzzles(n, m, a):
	aa = sorted(a)
	if n == m:
		k = max(a) - min(a)
	else:
		k = max(aa) - min(aa)
		for i in range(0, m - n + 1):
			x = max(aa[i:i + n]) - min(aa[i:i + n])
			if x < k:
				k = x
	return k
(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
print(puzzles(n, m, a))


(n, m) = map(int, input().split())
puzzles = list(map(int, input().split()))
puzzles.sort()
duzdi = float('inf')
for i in range(m - n + 1):
	duzdi = min(duzdi, puzzles[i + n - 1] - puzzles[i])
print(duzdi)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l = sorted(l)
for i in range(len(l) - n + 1):
	if i == 0:
		min = l[i + n - 1] - l[i]
		continue
	if min > l[i + n - 1] - l[i]:
		min = l[i + n - 1] - l[i]
print(min)


(n, k) = input().split(' ')
n = int(n)
k = int(k)
fs = input().split(' ')
fs = [int(f) for f in fs]
fs.sort()
mindiff = 1000000.0
for i in range(0, len(fs)):
	if i + n > len(fs):
		break
	if fs[i + n - 1] - fs[i] < mindiff:
		mindiff = fs[i + n - 1] - fs[i]
print(mindiff)


(n, m) = map(int, input().split())
arr = [int(i) for i in input().split()]
arr.sort()
l = 0
r = n - 1
ans = 10 ** 15
while r < m:
	ans = min(ans, arr[r] - arr[l])
	l += 1
	r += 1
print(ans)


(n, m) = map(int, input().split())
puzzles = list(map(int, input().split()))
puzzles.sort()
minDiff = 1000000000
for i in range(0, m - n + 1):
	diff = puzzles[i + n - 1] - puzzles[i]
	if diff < minDiff:
		minDiff = diff
print(minDiff)


(a, b) = map(int, input().split())
d = list()
s = list(map(int, input().split()))
s = sorted(s)
for i in range(b - a + 1):
	d.append(s[a - 1 + i] - s[i])
print(min(d))


(n, m) = map(int, input().split(' '))
num = list(map(int, input().split(' ')))
num.sort(reverse=True)
i = 0
mx = num[0] - num[0 + n - 1]
while i <= m - n:
	dif = num[i] - num[i + n - 1]
	if dif < mx:
		mx = dif
	i += 1
print(mx)


(n_students, n_puzzles) = map(int, input().split())
puzzles = sorted(list(map(int, input().split())))
least_diff = 9999
for i in range(n_puzzles - n_students + 1):
	diff = puzzles[i + n_students - 1] - puzzles[i]
	least_diff = min(least_diff, diff)
print(least_diff)


(n, m) = map(int, input().split())
data = [int(i) for i in input().split()]
if m == n:
	print(max(data) - min(data))
else:
	data.sort()
	ans = 999999999
	for i in range(m - n + 1):
		ans = min(ans, data[i + n - 1] - data[i])
	print(ans)


(n, m) = map(int, input().split())
sizes = sorted(list(map(int, input().split())))
best = 9999999999999999999
for i in range(0, m - n + 1):
	best = min(best, sizes[i + n - 1] - sizes[i])
print(best)


newlist = []
x = [int(item) for item in input().split()]
y = [int(item) for item in input().split()]
y.sort()
a = min(x)
b = max(x)
for b in range(b - a + 1):
	newlist.append(abs(y[b] - y[b + (a - 1)]))
print(min(newlist))


(x, y) = map(int, input().split())
a = [int(i) for i in input().split()]
a.sort()
best = 999999999
for i in range(y - (x - 1)):
	best = min(best, a[i + (x - 1)] - a[i])
print(best)


ip = input().split(' ')
ip2 = input().split(' ')
n = int(ip[0])
m = int(ip[1])
for i in range(m):
	ip2[i] = int(ip2[i])
ip2 = sorted(ip2)
mini = 10000
for x in range(m):
	if x + n - 1 > m - 1:
		break
	else:
		mini = min(mini, ip2[x + n - 1] - ip2[x])
print(mini)


a = input().split()
n = int(a[0])
m = int(a[1])
pintu = [int(x) for x in input().split()]
pintu.sort()
d = pintu[n - 1] - pintu[0]
for i in range(1, m - n + 1):
	di = pintu[i + n - 1] - pintu[i]
	d = min(d, di)
print(d)


l = input().split()
n = int(l[0])
m = int(l[1])
l1 = input().split()
l1 = list(map(int, l1))
l1.sort()
i = 0
j = n - 1
count = l1[j] - l1[i]
while j < m:
	if count > l1[j] - l1[i]:
		count = l1[j] - l1[i]
	i += 1
	j += 1
print(count)


def insert(a, v):
	i = 0
	while i < len(a) and v <= a[i]:
		a[i] = a[i + 1]
		i += 1
	a[i] = v
	return a
inp = input().split()
n = int(inp[0])
m = int(inp[1])
pls = list(map(int, input().split()))
pls.sort()
best = 10001
for i in range(m - n + 1):
	if abs(pls[i] - pls[i + n - 1]) < best:
		best = abs(pls[i] - pls[i + n - 1])
print(best)


ini = lambda : map(int, input().split())
(n, m) = ini()
b = sorted(ini())
print(min((j - i for (i, j) in zip(b, b[n - 1:]))))


(n, m) = [int(x) for x in input().split()]
f = [int(x) for x in input().split()]
f = sorted(f)
ans = f[m - 1] - f[0]
i = m - 1
while i - n + 1 >= 0:
	if f[i] - f[i - n + 1] <= ans:
		ans = f[i] - f[i - n + 1]
	i -= 1
print(ans)


x = str(input()).split()
x[0] = int(x[0])
x[1] = int(x[1])
p = str(input()).split()
for i in range(0, x[1]):
	p[i] = int(p[i])
p.sort()
d = p[x[0] - 1] - p[0]
i = 0
while i + x[0] - 1 < x[1]:
	if d > p[i + x[0] - 1] - p[i]:
		d = p[i + x[0] - 1] - p[i]
	i = i + 1
print(d)


(stu, puz) = map(int, input().split())
puz_list = list(map(int, input().split()))
puz_list.sort()
final = 1000
for i in range(puz - stu + 1):
	ans = puz_list[i + stu - 1] - puz_list[i]
	if final >= ans:
		final = ans
print(final)


import sys
(n, m) = list(map(int, sys.stdin.readline().rstrip().split(' ')))
l = list(map(int, sys.stdin.readline().rstrip().split(' ')))
l.sort(reverse=True)
ss = 10000
for i in range(m - n + 1):
	s = l[i] - l[i + n - 1]
	if s < ss:
		ss = s
print(ss)


def puzzles():
	(students, available) = map(int, input().split())
	puzzles = sorted(map(int, input().split()))
	min_difference = puzzles[students - 1] - puzzles[0]
	for i in range(1, available - students + 1):
		min_difference = min(min_difference, puzzles[i + students - 1] - puzzles[i])
	print(min_difference, end='')
puzzles()


(n, m) = [int(x) for x in input().split()]
ps = [int(x) for x in input().split()]
ps.sort()
dif = ps[len(ps) - 1] - ps[0]
for i in range(m - n + 1):
	newDif = ps[i + n - 1] - ps[i]
	if newDif < dif:
		dif = newDif
print(dif)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
mini = list()
a.sort(reverse=True)
for i in range(m - n + 1):
	b = a[i]
	c = a[i + n - 1]
	mini.append(b - c)
print(min(mini))


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


(n, m) = [int(i) for i in input().split()]
a = input().split()
l = []
for j in range(m):
	d = int(a[j])
	l.append(d)
b = sorted(l)
p = []
for i in range(m - n + 1):
	c = b[i + n - 1] - b[i]
	p.append(c)
mi = min(p)
print(mi)


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