import Data.Traversable
import Data.List

main :: IO ()
main = do
  (n:k:xs) <- ((map read) . words) <$> getLine
  ps <- for [1..n] $ \x ->
    read <$> getLine
  putStrLn . show $ solve k ps

solve :: Int -> [Int] -> Int
solve k xs =
  let sorted = sort xs
  in minimum $ map (\(a,b) -> b - a) $ zip sorted (drop (k-1) sorted)