#include #include #include using namespace std; struct BipartiteMaximumMatching { public: BipartiteMaximumMatching() {} BipartiteMaximumMatching(int p, int q) : p(p), q(q), g(p), match(q, -1) {} void add_directed_edge(int a, int b) { assert(0 <= a && a < p); assert(0 <= b && b < q); g[a].push_back(b); } int get_maximum_matching() { std::vector covered(p); std::vector dist(p); std::vector nx(p); int max_length; int res = 0; auto bfs = [&]() { std::queue que; for (int u = 0; u < p; u++) { if (!covered[u]) { que.push(u); dist[u] = 0; } else { dist[u] = -1; } } while (que.size()) { int u = que.front(); que.pop(); for (int v : g[u]) { if (match[v] == -1) { max_length = dist[u]; return; } if (match[v] != u) { dist[match[v]] = dist[u] + 1; que.push(match[v]); } } } }; auto dfs = [&](auto self, int u) -> bool { for (int &i = nx[u]; i < (int)g[u].size(); i++) { for (int v : g[u]) { int w = match[v]; if (w == -1 || (dist[w] == dist[u] + 1 && dist[w] < max_length && self(self, w))) { match[v] = u; covered[u] = true; return true; } } } return false; }; while (true) { max_length = -1; bfs(); if (max_length == -1) { return res; } for (int u = 0; u < p; u++) { res += (dist[u] == 0 && dfs(dfs, u)); } } } std::vector> get_matching_edges() { std::vector> res; for (int v = 0; v < q; v++) { if (match[v] >= 0) { res.push_back(std::pair(match[v], v)); } } return res; } private: int p, q; std::vector> g; std::vector match; }; int main() { int n, m; cin >> n >> m; BipartiteMaximumMatching g(n, n); bool b[200005]{0}; for(int i = 0; i < m; i++) { int u, v; cin >> u >> v; u--; v--; b[u] = b[v] = true; g.add_directed_edge(u, v); g.add_directed_edge(v, u); } int ans = g.get_maximum_matching() * 2; int c = 0; for(int u = 0; u < n; u++) { c += b[u]; } if(ans == n * 2 - 2 && c == n - 1) { ans -= 2; } cout << ans - n << endl; }