#include <algorithm>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#define MAXN 100005
using namespace std;
ifstream cin ("sent.in");
ofstream cout ("sent.out");
int n, m, a, b, len, cnt;
vector <int> eto[MAXN];
int blocks[MAXN], hash[MAXN];
void DfsEdges (int x, int now)
{
len = eto[now].size ();
for (int i = 0; i < len; i ++)
{
blocks[eto[now][i]] = x;
DfsEdges (x, eto[now][i]);
}
}
void FindBlocks (void)
{
for (int i = 1; i <= n; i ++)
if (blocks[i] == i)
DfsEdges (i, i);
}
int CountAns (void)
{
for (int i = 1; i <= n; i ++)
hash[blocks[i]] ++;
for (int i = 1; i <= n; i ++)
if (hash[i] > 1)
cnt ++;
int ans = cnt - 1;
memset (hash, 0, sizeof (hash));
for (int i = 1; i <= n; i ++)
if (eto[i].size () % 2)
hash[blocks[i]] ++;
for (int i = 1; i <= n; i ++)
if (hash[i] > 2)
ans += (hash[i] - 2) / 2;
return ans;
}
int main ()
{
cin >> n >> m;
for (int i = 1; i <= m; i ++)
{
cin >> a >> b;
eto[a].push_back (b);
}
for (int i = 1; i <= n; i ++)
blocks[i] = i;
FindBlocks ();
cout << CountAns () << endl;
return 0;
}