import Data.List

main = do
  [_,k] <- map read.words <$> getLine
  hs    <- map read.lines <$> getContents
  print $ solve k $ sort hs

solve :: Int -> [Int] -> Int
solve k hs = minimum ds
  where
  ds = go hs as
  go _ [] = []
  go (b:bs) (a:as) = a-b : go bs as
  as = drop (k-1) hs
