import Data.List (sort)

main :: IO ()
main = do
    (_:k:hs) <- map read . words <$> getContents
    print $ minDiff k (sort hs)

minDiff :: Int -> [Int] -> Int
minDiff k xs = minimum diffs
  where
    diffs = zipWith (-) ys xs
    ys    = drop (k-1) xs
