import scala.io.StdIn.readLine

object Main {
  def main(args: Array[String]): Unit = {
    val Array(n, k) = readLine.split(" ").map(_.toInt)
    val trees: List[Int] = (0 until n).map(_ => readLine.toInt).toList

    println((0 to n - k).map(i => trees(i + k - 1) - trees(i)).min)
  }
}
