import Data.List

differ :: Int -> [Int] -> Int
differ k l = dif (eval c) c (drop k sl) where
    sl = sort l
    c  = take k sl
    dif m _ [] = m
    dif m (x:xs) (y:ys)
        | d < m     = dif d cl ys
        | otherwise = dif m cl ys  
        where
            cl = xs ++ [y]
            d  = eval cl
    eval (x:xs) = last xs - x

readData :: Int -> IO [Int]
readData 0 = return []
readData n = do
    stX <- getLine
    let x = read stX :: Int
    fmap (x:) $ readData (n-1)
        
main :: IO() 
main = do
    line1 <- getLine
    let [stN, stK] = words line1
        n = read stN :: Int
        k = read stK :: Int
    l <- readData n
    let ans = differ k l 
    print ans
