#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); int n, m; cin >> n >> m; vector in(n + 1), out(n + 1); for (int i = 0; i < m; ++i) { int u, v; cin >> u >> v; ++out[u]; ++in[v]; } long long hi = 0, lo = 0; for (int i = 1; i <= n; ++i) { if (in[i] > out[i]) hi += in[i] - out[i]; if (out[i] > in[i]) lo += out[i] - in[i]; } cout << max(0ll, max(hi, lo) - 1) << endl; return 0; }