#include <bits/stdc++.h>
using namespace std;
int n,k;
const int N=1e5+10;
bool st[N];
int x,y,res;
int main(){
cin>>n>>k;
st[0]=true;
while(k--){//时间复杂度降低,变为O(N)
cin>>x>>y;
if(st[y]==false) res+=1;
st[x]=true;//一定要先判断再更新,否则如果出现了“3 3”这样的样例,无论3在之前的样例中是否被初始化,
//都会更新为true,导致res少加
}
cout<<res;
return 0;
}