/*简单来说就是右边y的必须要先在左边出现过,否则res+1,所
以用一个数组将左边出现过的次数加一即可,但是要排除右边的
输入如果是零,则是常数,res不用增加*/
#include<iostream>
using namespace std;
const int N=1e5+10;
int a[N];
int main()
{
int n,k,res=0;
cin>>n>>k;
while(k--){
int x,y;
cin>>x>>y;
if(a[y]==0&&y!=0)res++;
a[x]++;
}
cout<<res;
return 0;
}