import Control.Monad
import Data.List

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