import Control.Monad
import Data.List

main :: IO ()
main = do
    n <- readLn
    facts <- replicateM n $ map read . words <$> getLine
    print $ solve facts

solve :: [[Int]] -> Int
solve = sum . head . sortOn (negate . head)