#include #include using namespace std; int main( void ) { int N, M; cin >> N >> M; vector in( N + 1, 0 ), out( N + 1, 0 ); int u, v; for( int i = 0; i < M; i++ ) { cin >> u >> v; if( u == v ) continue; in[v]++, out[u]++; } int num = 0; for( int i = 1; i <= N; i++ ) { num += abs( in[i] - out[i] ); } if( num == 0 || num == 2 ) { cout << 0 << endl; } else { cout << num / 2 - 1 << endl; } return 0; }