#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace::std; template ostream& operator<< (ostream& o, const pair& p) { o << "<" << p.first << ", " << p.second << ">"; return o; } template ostream& operator<< (ostream& o, const vector& v) { for (const auto& x : v) o << x << " "; return o; } template ostream& operator<< (ostream& o, const set& v) { for (const auto& x : v) o << x << " "; return o; } template ostream& operator<< (ostream& o, const deque& v) { for (const auto& x : v) o << x << " "; return o; } template ostream& operator<<(ostream& o, const unordered_map& m) { o << "{"; for (const auto& [k, v] : m) o << " " << k << ": " << v << ","; o << "}"; return o; } template ostream& operator<< (ostream& o, const vector>& v) { for (const auto& x : v) o << x << endl; return o; } ostream& operator<< (ostream& o, const vector& v) { for (const auto& x : v) o << x << endl; return o; } template istream& operator>> (istream& i, vector& v) { for (auto& x : v) i >> x; return i; } istream& operator>> (istream& i, pair& p) { i >> p.first >> p.second; return i; } int main() { ios::sync_with_stdio(false); long long n, m; cin >> n >> m; vector< long long> c(n + 1); vector> e(n + 1); for ( long long i = 0; i < m; ++i) { long long u, v; cin >> u >> v; e[u].push_back(v); e[v].push_back(u); --c[u]; ++c[v]; } //cerr << "e " << e << endl; long long o = 0; vector v(n + 1); vector q; for (int s = 1; s <= n; ++s) if (!v[s]) { // cerr << "s: " << s << endl; bool ok = true; int count = 0; q.push_back(s); while (q.size()) { int x = q.back(); q.pop_back(); // cerr << "checking x " << x << endl; if (v[x]) continue; // cerr << "visiting x " << x << endl; v[x] = true; ok &= c[x] == 0; count += e[x].size(); for (int y : e[x]) { // cerr << "pushing y " << y << endl; q.push_back(y); } } // cerr << "s " << s << " ok " << ok << " count " << count << endl; o += ok && count > 1; } long long hi = 0; for ( long long i = 0; i <= n; ++i) { if (c[i] > 0) hi += c[i]; } if (o == 0) { cout << max(0ll, hi- 1) << endl; } else if (hi == 0) { cout << max(0ll, o - 1) << endl; } else { cout << max(0ll, hi + o - 1) << endl; } return 0; }