program heaven;
var a:array[1..366] of boolean;
m,d,i,j,k,n:integer; max:longint;
begin
fillchar(a,sizeof(a),true);
assign(input,'heaven.in');
reset(input);
assign(output,'heaven.out');
rewrite(output);
readln(n);
for i:=1 to n do
begin
readln(m,d);
for j:=1 to m-1 do
case j of
1,3,5,7,8,10,12:k:=k+31;
2:k:=k+29;
4,6,9,11:k:=k+30;
end;
k:=k+d;
a[k]:=false;
k:=0;
end;
for i:=1 to 366 do
if a[i] then begin k:=k+1; if k>max then max:=k; end else k:=0;
max:=round((max/366)*24*3600);
writeln(max);
end.