
function Main(input) {
    var lines = input.split("\n");
    var l0 = lines.shift().split(" ");
    var N = l0[0] - 0;
    var K = l0[1] - 0;
    var hs = lines.map(function(value) { return value - 0; }).sort(function(a,b) { return b - a; });
    var min = Number.MAX_VALUE;
    for (var n = 0; n < N - K + 1; n++) {
        min = Math.min(min, hs[n] - hs[n+K-1]);
    }

    console.log(min);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
