import Data.List
import Control.Monad

minDiff :: Int -> [Int] -> Int
minDiff k xs = minimum $ zipWith (-) (drop (k - 1) xs') xs'
  where xs' = sort xs

main :: IO ()
main = do
  [n, k] <- mapM readIO . words =<< getLine
  xs <- replicateM n (readIO =<< getLine)
  print $ minDiff k xs