program pk;
var i,j,k,n,m,ans,x,y:longint;
can:boolean;
link:array[1..100,1..100]of boolean;
begin
assign(input,'contest.in');
reset(input);
assign(output,'contest.out');
rewrite(output);
readln(n,m);
for i:=1 to m do
begin
readln(x,y);
link[x,y]:=true;
end;
for k:=1 to n do
for i:=1 to n do
for j:=1 to n do
link[i,j]:=(link[i,j])or(link[i,k] and link[k,j]);
for i:=1 to n do
begin
can:=true;
for j:=1 to n do
if (i<>j)and(not link[i,j])and(not link[j,i]) then can:=false;
if can then inc(ans);
end;
writeln(ans);
close(input);
close(output);
end.