#include<bits/stdc++.h>
using namespace std;
const int N=100010;
bool st[N];
int main()
{
int n,k;cin >> n >> k;st[0]=true;int ans=0;
while(k--)
{
int x,y;cin >> x >> y;
if(!st[y])ans++; //右值未被使用时统计总数加1
st[x]=true;
}
cout << ans;
return 0;
}