import qualified Data.ByteString.Lazy.Char8 as B
import qualified Data.IntMap as M
import Data.Maybe

main :: IO ()
main = do
  (n:as) <- map readB . B.words <$> B.getContents
  print $ solve n as

readB :: B.ByteString -> Int
readB = fst . fromJust . B.readInt

solve :: Int -> [Int] -> Int
solve n = median n 0 . M.toAscList . M.adjust pred 0 . count

count :: [Int] -> M.IntMap Int
count [] = M.singleton 0 1
count (a:as) = m2
  where
    m0 = count as
    m1 = M.mapKeys (+ a) m0
    m2 = M.unionWith (+) m0 m1

median :: Int -> Int-> [(Int, Int)] -> Int
median n k ((a, b):xs)
  | n <= k' * 2 = a
  | otherwise = median n k' xs
  where 
    k' = k + a * b
 