let R() = stdin.ReadLine()
let n, k = let t = R().Split() |> Array.map int in t.[0], t.[1]
let h = Array.init n (fun _ -> R() |> int)

h
|> Array.sort
|> Array.windowed k
|> Array.map(fun xs ->
    let min = xs.[0]
    let max = xs.[k - 1]
    max - min)
|> Array.min
|> stdout.WriteLine
