import Control.Monad
import Data.List

main = do
    [n,k] <- map read . words <$> getLine
    hs <- replicateM n readLn
    let sHs = sort hs
    print $ minimum $ zipWith (-) (tailN (k-1) sHs) sHs

tailN :: Int -> [Int] -> [Int]
tailN n (x:xs) 
    | n == 1 = xs  
    | otherwise = tailN (n-1) xs


-- fold or zipwithで書きたい