program heaven;
var
n,i,j,a,b,m,max,temp:longint;
mon:array[1..12]of longint;
day:array[1..366]of 0..1;
begin
assign(input,'heaven.in');
assign(output,'heaven.out');
reset(input);
rewrite(output);
mon[1]:=31;
mon[2]:=29;
mon[3]:=31;
mon[4]:=30;
mon[5]:=31;
mon[6]:=30;
mon[7]:=31;
mon[8]:=31;
mon[9]:=30;
mon[10]:=31;
mon[11]:=30;
mon[12]:=31;
readln(n);
fillchar(day,sizeof(day),0);
for i:=1 to n do
begin
readln(a,b);
m:=0;
for j:=1 to a-1 do
m:=m+mon[j];
m:=m+b;
day[m]:=1;
end;
max:=0;
temp:=0;
for i:=1 to 366 do
begin
if day[i]=0 then temp:=temp+1 else begin
if max<temp then max:=temp;
temp:=0;
end;
end;
if (max/366*24*60*60)-trunc(max/366*24*60*60)>=0.5 then writeln(trunc(max/366*24*60*60)+1) else
writeln(trunc(max/366*24*60*60));
close(input);
close(output);
end.