import Control.Monad
import Data.List

main = do
  [n, k] <- map read . words <$> getLine
  hs <- replicateM n $ readLn
  print $ minimum $ func k $ sort hs
  
func :: Int -> [Int] -> [Int]
func k xs = zipWith (-) (drop (k - 1) xs) xs