import Control.Monad
import Data.List

diff :: Int -> [Int] -> [Int]
diff k xs = map (\(a, b) -> b - a) l
    where
        l = zip xs (drop k xs)

main = do
    first <- fmap words getLine
    let n = read (first !! 0) :: Int
    let k = read (first !! 1) :: Int
    trees <- replicateM n getLine
    let trees' = fmap read trees :: [Int]
    let sorted = sort trees'
    putStrLn $ show . minimum $ diff (k-1) sorted
    