#include<iostream>
using namespace std;
const int N = 100010;
int n, m;
bool st[N];
int main()
{
scanf ("%d%d", &n, &m);
int res = 0;
for (int i = 0; i < m; i ++ )
{
int x, y;
scanf ("%d%d", &x, &y);
if (st[y] || y == 0) st[x] = true;
else
{
st[x] = true;
res ++ ;
}
}
cout << res << endl;
return 0;
}