var n,i,ans,time,j:longint;
a,b:array[0..1000]of longint; nv,lv:Array[0..1000]of boolean;
f:boolean;
function check(t,i:longint):boolean;
begin
if (i=0)or(i=n+1) then exit(true);
if (t mod (a[i]+b[i])>0)and(t mod (a[i]+b[i])<=a[i])then exit(true)
else exit(false);
end;
begin
assign(input,'rivera.in');assign(output,'rivera.out');
reset(input);rewrite(output);
ans:=maxlongint; fillchar(lv,sizeof(lv),0);
readln(n); for I:=1 to n do readln(a[i],b[i]);
time:=0; lv[0]:=true;
repeat
inc(time);f:=false;
fillchar(nv,sizeof(nv),0);
for i:=0 to n+1 do if check(time,i) then
for j:=i-5 to i+5 do
if (j>=0)and(j<=n+1)and(lv[j]) then nv[i]:=true;
if nv[n+1]then begin ans:=time;break;end;
//for i:=0 to n+1 do if nv[i]then write(i,' ');writeln;
lv:=nv; //if f=false then break;
until time>2555;
if ans>100000 then writeln('NO') else writeln(ans);
close(output);
end.