import Data.List

subMaxMin a = maximum a - minimum a

solve n 0 _ = 0
solve n m as@(_:xs)
  | n > length as = m
  | otherwise = let m' = min m (subMaxMin . take n $ as)
                 in solve n m' xs

main :: IO ()
main = do
    [n,k] <- map read . words <$> getLine :: IO [Int]
    h <- map read . lines <$> getContents :: IO [Int]
    print . solve k (maximum h) $ sort h
