
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).map(n => parseInt(n ,10))
 
  var hSort = []
  h.forEach(rawH => {
    var b = hSort.some((sortH, j)=> {
      if(sortH >= rawH) {
        hSort.splice(j, 0, rawH)
        return true
      } else {
        return false
      }
    })
    if(!b) { hSort.push(rawH) }
  })
  
  var min = undefined
  for(var i = 0; i <= hSort.length - k; i++) {
    var abs = Math.abs(hSort[i] - hSort[i + k -1])
    if(min > abs || min == undefined) {
      min = abs
    }
  }
  console.log(min)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
