import Data.List
main=do
 getLine
 xd<-sort.map((\[x,d]->(x,d)).map read.words).lines<$>getContents
 print$(1+)$snd$head xd
f r ws vs[]=r
f r(w:ws)(v:vs)((x,d):xd)
 |w<x+d=f r ws vs((x,d):xd)
 |otherwise=f nr(x:w:ws)(nr:v:vs)xd where nr=(r+v)`mod`998244353