import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as B
main=print.solve.map(map(fst.fromJust.B.readInt).B.words).B.lines=<<B.getContents
solve([n]:xls)=fst.foldr f (0,maxBound).sortOn(uncurry(-))$map(\[x,l]->(x,l))xls
f(x,l)(i,p)=if x+l>p then (i,p) else (i+1,x-l)