uses math;
var a,b:array[1..1010]of longint;
v:array[0..1000,0..1010]of boolean;
i,j,k,mx,n:longint;
begin
assign(input,'rivera.in');reset(input);
assign(output,'rivera.out');rewrite(output);
readln(n);a[n+1]:=10000;b[n+1]:=10000;
for i:=1 to n do readln(a[i],b[i]);mx:=990;
for i:=0 to mx do v[i,0]:=true;i:=0;
while i<=mx do
begin
for j:=0 to n+1 do
begin
if (i=302)and(j=997) then
begin k:=1;end;
if v[i,j]=true then
for k:=-5 to 5 do
if (j+k<=n+1)and(j+k>0)and(not(v[i+1,j+k]))then
if i mod (a[j+k]+b[j+k])+1<=a[j+k]then
begin
v[i+1,j+k]:=true;
if j+k=n+1 then begin writeln(i+1);close(output);halt;end;
end;end;
inc(i);
end;
writeln('NO');
close(output);
end.