differ :: Int -> [Int] -> Int
differ k l = dif (eval c) c (drop k sl) where
    sl = msort 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 = iter (10^9) 1 where
        iter min max [] = max - min 
        iter min max (x:xs) 
            | x < min = iter x max xs
            | x > max = iter min x xs
            | otherwise = iter min max xs

msort :: Ord a => [a] -> [a]
msort []    = []
msort [x]   = [x]
msort [x, y]
    | x <= y    = [x, y]
    | otherwise = [y, x]
msort xs = merge (msort (take n xs)) (msort (drop n xs))
    where
        n = div (length xs) 2
        merge ax@(x:xs) ay@(y:ys) 
            | x <= y    = x:(merge xs ay)
            | otherwise = y:(merge ax ys)
        merge xs [] = xs
        merge [] ys = ys
        
readData :: Int -> IO [Int]
readData 0 = return []
readData n = do
    x <- readLn :: IO 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
