import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import Prelude hiding (readLn)

main :: IO ()
main = readLine >>= main'
    where
        main' [n, k] = replicateM n readLn >>= print . solve k . sort

solve :: Int -> [Int] -> Int
solve k hs = minimum . map mf . zip hs $ drop (k - 1) hs
    where
        mf (hmin, hmax) = hmax - hmin

readLn :: IO Int
readLn = head <$> readLine

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine