var n,s,r,t,l,m,d,k,t1,m1,m2,k1:integer;
begin
read(n,s,r);
read(k,k1);
read(m,m1,m2);
if ((m+1)<>k) and ((m1+1)<>k) and ((m2+1)<>k) then t:=t+1;
if ((m-1)<>k) and ((m1-1)<>k) and ((m2-1)<>k) then t1:=t1+1;
d:=t+t1;
writeln(d);
end.
