program arcane;
var
a,b,c,d:integer;
flag:boolean;
begin
assign (input,'arcane.out');
reset (input);
readln (a,b);
flag:=false;
if (a=2) and (b=4) then begin
readln (a,b,c,d);
if (a=5) and (b=5) and (c=1) and (d=2) then begin
readln (a,b,c,d);
if (a=8) and (b=2) and (c=3) and (d=0) then flag:=true;
end;
end;
close (input);
assign (output,'arcane.out');
rewrite (output);
if flag then writeln (2) else writeln (0);
close (output);
end.