var n,i,j,k,l:longint;
a,b:array[1..1000]of longint;
q:array[0..1,0..1010]of longint;
p:array[0..1]of longint;
v:Array[0..1010]of boolean;
function fit(x,y:longint):boolean;
var i,j:longint;
begin
if y=0 then exit(true);
if y=n+1 then exit(true);
i:=x mod(a[y]+b[y]);
if i=0 then exit(false);
if i<=a[y] then exit(true) else exit(false);
end;
begin
assign(input,'rivera.in'); assign(output,'rivera.out');
reset(input); rewrite(output);
readln(n);
for i:=1 to n do readln(a[i],b[i]);
q[0,0]:=0; p[0]:=1;
for i:=1 to 10000 do
begin
fillchar(v,sizeof(v),false);
for j:=1 to p[(i+1) and 1] do
begin
for k:=q[i and 1,j]-5 to q[i and 1,j]+5 do
if k=n+1 then
begin
write(i);
close(input); close(output);
halt;
end
else
if(k>=0)and(k<=n+1)and(fit(i,k))and not(v[k])then
begin
inc(p[i and 1]);
q[(i+1)and 1,p[i and 1]]:=k;
v[k]:=true;
end;
p[(i+1)and 1]:=0;
end;
end;
write('NO');
close(input); close(output);
end.