import Control.Monad
import Data.List

main = do
  [n, k] <- map read . words <$> getLine
  hs <- replicateM n $ readLn
  let xs = func k $ reverse $ sort hs
  print $ head $ sort xs
  
func :: Int -> [Int] -> [Int]
func k (x:xs)
  | (length xs < k - 1) = []
  | otherwise       = x - (last $ take (k - 1) xs) : func k xs