#include using namespace std; int main(){ int N, M; cin >> N >> M; vector> E(N); vector> E2(N); for (int i = 0; i < M; i++){ int U, V; cin >> U >> V; U--; V--; E[U].push_back(V); E2[U].push_back(V); E2[V].push_back(U); } int cc = 0; vector c(N, -1); for (int i = 0; i < N; i++){ if (c[i] == -1 && !E2[i].empty()){ c[i] = cc; queue Q; Q.push(i); while (!Q.empty()){ int v = Q.front(); Q.pop(); for (int w : E2[v]){ if (c[w] == -1){ c[w] = c[v]; Q.push(w); } } } cc++; } } vector in(N, 0), out(N, 0); for (int i = 0; i < N; i++){ for (int j : E[i]){ out[i]++; in[j]++; } } if (cc == 1){ int a = 0; for (int i = 0; i < N; i++){ a += abs(in[i] - out[i]); } cout << (a - 2) / 2 << endl; } else { assert(false); vector D(cc, 0); for (int i = 0; i < N; i++){ if (!E[i].empty()){ D[c[i]] += abs(in[i] - out[i]); } } int ans = 0; for (int i = 0; i < cc; i++){ ans += max(D[i], 2); } ans -= 2 * (cc - 1); ans /= 2; cout << ans << endl; } }