fun main (args : Array<String>) {
	val (n, k) = readLine()!!.split(" ")
	val N : Int = n.toInt()
	val K : Int = k.toInt()
	var list : MutableList<Long> = mutableListOf()
	var calc : Long
	var result : Long = 0
	for (i in 0..N - 1) {
		val h = readLine()
		list.add(h!!.toLong())
	}
	list.sort()
	for (i in 0..N - K) {
		calc = list[i + (K - 1)] - list[i]
		if (i == 0) {
			result = calc
		}
		if (result > calc) {
			result = calc
		}
	}
	println("${result}")
}