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,l,r: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 k:=0 to n+1 do f[i,k]:=false;
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;
if j-5<0 then l:=0 else l:=j-5;
if j+5>n+1 then r:=n+1 else r:=j+5;
for ll:=l to r do
begin
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.