import Control.Applicative
import Control.Monad
import Data.List

main :: IO ()
main = do
  [n, k] <- f
  solve k <$> replicateM n readLn >>= print
  where
    f = map read <$> words <$> getLine

solve :: Int -> [Int] -> Int
solve k xs = let ss = sort xs
             in f (10^9) ss (drop (k - 1) ss)
  where
    f mn as [] = mn
    f mn (a:as) (b:bs) = f (min mn (b - a)) as bs
