import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Control.Monad
import Data.List
import Data.Maybe

main = do
  [n,k] <- map read . words <$> getLine :: IO [Int]
  hs <- fmap VU.fromList $ fmap sort $ (replicateM n $ do
    (i,_) <- fromJust  . B.readInt <$> B.getLine 
    return i)
  xs <- VU.forM (VU.fromList [k-1..n-1]) $ \i -> return $ (hs VU.! i) - (hs VU.! (i-k+1))
  print $ VU.minimum xs 
