import Data.List (sort)

main = do
    line <- getLine
    let [_, k] = map read . words $ line
    putStrLn . show . solve k . map read . lines =<< getContents

solve :: Int -> [Int] -> Int
solve k ns =
    let sorted = sort ns
        shifted = drop (k - 1) sorted
        diffs = zipWith (-) shifted sorted
    in  minimum diffs
