function Main(input) {
  input = input.split("\n")

  var n = parseInt(input[0].split(" ")[0], 10)
  var k = parseInt(input[0].split(" ")[1], 10)
  var h = input.slice(1, n + 1)

  var hSort = h.sort()
  
  var hAbs = []
  for(var i = 0; i <= hSort.length - k; i++) {
    hAbs.push(Math.abs(hSort[i] - hSort[i + k -1]))
  }
  console.log(hAbs.reduce((h1, h2) => h1 > h2? h2: h1))
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));