#include using namespace std; using ll = long long; template istream& operator >> (istream& is, vector& vec) { for(T& x : vec) is >> x; return is; } template ostream& operator << (ostream& os, const vector& vec) { if(vec.empty()) return os; os << vec[0]; for(auto it = vec.begin(); ++it != vec.end(); ) os << ' ' << *it; return os; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, m, u, v; cin >> n >> m; vector in(n), out(n); for(int i = 0; i < m; i++){ cin >> u >> v; u--, v--; in[u]++; out[v]++; } ll s = 0, s1 = 0; for(int i = 0; i < n; i++){ if(in[i] >= out[i]) s += in[i] - out[i]; else s1 += out[i] - in[i]; } cout << max(0ll, s1 - 1) << '\n'; }