#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int n,visit[505],edge[505][505],link[505];
bool hungery(int m){
for(int i=1;i<=n;i++){
if(edge[m][i]&&!visit[i]){
visit[i] = 1;
if(link[i]==0||hungery(link[i])){
link[i] = m;
return true;
}
}
}
return false;
}
int main(){
int i,j,k,r,c,count;
memset(edge,0,sizeof edge);
scanf("%d%d",&n,&k);
for(i=1;i<=k;i++){
scanf("%d%d",&r,&c);
edge[r][c] = 1;
}
// for(i=1;i<=n;i++){
// for(j=1;j<=n;j++){
// cout<<edge[i][j]<<" ";
// }
// cout<<endl;
// }
count = 0;
for(i=1;i<=n;i++){
memset(visit,0,sizeof visit);
if(hungery(i))
count++;
}
cout<<count<<endl;
return 0;
}