s=require("fs").readFileSync("/dev/stdin","utf8");

A = s.split('\n')
B = A[0].split(' ')[0] | 0
C = A[0].split(' ')[1] | 0

a = [...Array(B)].map((_, i) => A[i + 1] | 0)
a.sort((a,b) =>a < b ? -1 : 1)
l = C - 1
b = [...Array(a.length - l)].map((_, i) => a[i + l] - a[i])
console.log(Math.min(...b))
