fun main(args:Array<String>) {
    val (treeCount, decoCount) = readLine()!!.split(" ").map { it.toInt() }
    val treeList = (1..treeCount).map { readLine()!!.toLong() }.sorted()

    var min = 1000000000.toLong()
    for(i in (0..(treeList.size - decoCount))) {
        min = Math.min(min, Math.abs(treeList[i + decoCount - 1] - treeList[i]))
    }
    println(min)
}
