var
s:array[1..366] of integer;
i,n,mo,da,u,max:integer;
r,w:text;
begin
assign(r,'heaven.in');
assign(w,'heaven.out');
reset(r);
rewrite(w);
//while not(eof) do
//begin
readln(r,n);
for i:=1 to n do
begin
readln(r,mo,da);
case mo of
2:da:=da+31;
3:da:=da+31+29;
4:da:=da+2*31+29;
5:da:=da+2*31+29+30;
6:da:=da+3*31+29+30;
7:da:=da+3*31+29+30*2;
8:da:=da+4*31+29+30*2;
9:da:=da+5*31+29+30*2;
10:da:=da+5*31+29+30*3;
11:da:=da+6*31+29+30*3;
12:da:=da+6*31+29+30*4;
end;
s[da]:=1;
end;
for i:=1 to 366 do
if s[i]=0 then
begin
u:=u+1;
if max<u then
max:=u;
end
else
u:=0;
writeln(w,max/366*24*60*60:0:0);
//end;
close(r);
close(w);
end.