object Main extends App {
  val in = io.Source.stdin.getLines.toIndexedSeq
  val K = in.head.split(' ').map(_.toInt).apply(1)
  val ls = in.tail.map(_.toInt).toArray.sorted
  //println(K)
  //println(ls)
  
  val ret = (0 to ls.size - K).foldLeft(Int.MaxValue){ (a,i) =>
    val diff = Math.abs(ls(i) - ls(i+K-1))
    Math.min(a, diff)
  }
  println(ret)
}
