program project1;
var a,b:array[-10..1050] of longint;
f:array[0..1,-10..1050] of boolean;
n:longint;
procedure init;
var i:longint;
begin
assign(input,'rivera.in ');reset(input);
assign(output,'rivera.out');rewrite(output);
read(n);
for i:=1 to n do
read(a[i],b[i]);
end;
procedure main;
var t,i,ii,j,k,ll:longint;
begin
f[0,0]:=true;t:=0;
while true do
begin
inc(t);if t>10000 then begin writeln('NO');halt;end;
i:=t and 1;ii:=(t+1)and 1;
for j:=0 to n+1 do
begin
if not((j=0)or(j=n+1)) then
k:=t mod (a[j]+b[j]);
if (k>=1)and(k<=a[j])or((j=0)or(j=n+1)) then
begin
f[i,j]:=false;
for ll:=j-5 to j+5 do
begin
if ll<0 then continue;
if ll>n+1 then break;
if f[ii,ll] then begin f[i,j]:=true;break;end;
end;
end else f[i,j]:=false;
end;
if f[i,n+1] then
begin
writeln(t);
halt;
end;
end;
close(input);
close(output);
end;
begin
init;
main;
end.