#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 in_num = 0, out_num = 0; for( int i = 1; i <= N; i++ ) { if( in[i] > out[i] ) { in_num += in[i] - out[i]; } else if( in[i] < out[i] ) { out_num += out[i] - in[i]; } } if( ( in_num == 0 && out_num == 0 ) || ( in_num == 1 && out_num == 1 ) ) { cout << 0 << endl; } else { cout << in_num / 2 << endl; } return 0; }