#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1e5+10;
bool st[N];
int main()
{
int n,m;
cin>>n>>m;
int ans=0;
while (m -- )
{
int x,y;
cin>>x>>y;
if(!st[y]&&y) ans++;
st[x]=true;
}
cout<<ans<<endl;
return 0;
}