let n, k = Scanf.scanf " %d %d" @@ fun a b -> a, b
let hs = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let ans = ref max_int
let _ = Array.sort (-) hs; for i = 0 to n - k do ans := min !ans @@ hs.(k + i - 1) - hs.(i) done; Printf.printf "%d\n" !ans