#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
typedef long long ll;
using namespace std;
const int maxn=1e3+5,INF=0x3f3f3f3f;
ll n,m,girls[maxn],vis[maxn],ans;
vector<ll> g[maxn];
inline ll read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')w=-1;ch=getchar();
}
while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar();
return s*w;
}
bool Find(ll u){
for(int i=0;i<g[u].size();i++){
ll v=g[u][i];
if(!vis[v]){
vis[v]=1;
if(girls[v]==0||Find(girls[v])){
girls[v]=u;
return 1;
}
}
}
return 0;
}
int main(){
//freopen("a.in","r",stdin);
for(int i=0;i<maxn;i++){
g[i].clear();
}
n=read(),m=read();
for(int i=1;i<=m;i++){
ll u=read(),v=read();
g[u].push_back(v);
}
for(int i=1;i<=n;i++){
memset(vis,0,sizeof(vis));
if(Find(i))ans++;
}
cout<<ans;
}
疯狂搞板子