-- リストをソートする
-- p 番目の要素と p+(k-1) 番目の要素の差を調べ，最小となるpを出力

import Control.Applicative
import Control.Monad as M
import Data.List

solve :: [Int] -> Int -> Int -> Int
solve trees k n = negate $ maximum $ solve' (sort trees) k n where
  solve' :: [Int] -> Int -> Int -> [Int]
  solve' trees k n
    | (length trees) < k = []
    | otherwise = ((trees !! 0) - (trees !! (k-1))) : solve' (tail trees) k n

main :: IO ()
main = do
  [n, k] <- map read . words <$> getLine
  trees <- M.replicateM n getLine
  putStrLn $ show $ solve (map read trees) k n
