1 #include<cstdio>
2 #include<cstring>
3 #include<iostream>
4
5 using namespace std;
6
7 int match[505], vis[505], g[505][505], n;
8
9 inline int dfs(int u){
10 for(int i = 1; i <= n; i++){
11 if(g[u][i] && !vis[i]){
12 vis[i] = 1;
13 if(!match[i] || dfs(match[i])){
14 match[i] = u;
15 return 1;
16 }
17 }
18 }
19 return 0;
20 }//匈牙利
21
22 inline int hungary(){
23 int ans = 0;
24 for(int i = 1; i <= n; i++){
25 memset(vis, 0, sizeof(vis));
26 if(dfs(i)) ans++;
27 }
28 return ans;
29 }
30
31 int main(){
32 int k;
33 while(~scanf("%d%d", &n, &k)){
34 for(int i = 1; i <= k; i++){
35 int r, c;
36 scanf("%d%d", &r, &c);
37 g[r][c] = 1;
38 }
39 printf("%d
", hungary());
40 }
41 return 0;
42 }