import           Control.Monad
import           Data.List
import           Data.Maybe
import qualified Data.ByteString.Char8         as C8

getInt :: IO Int
getInt = fmap (fst . fromJust . C8.readInt) C8.getLine

getInts :: IO [Int]
getInts = fmap (map (fst . fromJust . C8.readInt) . C8.words) C8.getLine

main :: IO ()
main = do
    [n, k] <- getInts
    hs     <- replicateM n $ getInt
    print $ solve k (sort hs)

solve :: Int -> [Int] -> Int
solve k hs = minimum . zipWith (-) (drop (k - 1) hs) $ hs
