//cogs 728. [网络流24题] 最小路径覆盖问题
#include<iostream>
#include<climits>
#include<cstdio>
#include<queue>
#include<cstring>
#define inf 1e9+7
#define M(a) memset(a,0,sizeof a)
#define fo(i,j,k) for(i=j;i<=k;i++)
using namespace std;
const int mxn=10005;
queue <int> q;
bool bs[mxn],bt[mxn];
int n,m,s,t,ans,cnt;
int head[mxn],dis[mxn],pre[mxn],next[mxn];
struct node {int to,num,next,flow;} f[mxn<<2];
inline void add(int u,int v,int flow) //num:边的编号
{
f[++cnt].to=v,f[cnt].next=head[u],f[cnt].flow=flow,head[u]=cnt;
f[++cnt].to=u,f[cnt].next=head[v],f[cnt].flow=0,head[v]=cnt;
}
inline bool bfs()
{
int i,j,u,v,flow;
q.push(s);
memset(dis,-1,sizeof dis);
dis[s]=0;
while(!q.empty())
{
u=q.front();
q.pop();
for(i=head[u];i;i=f[i].next)
{
v=f[i].to,flow=f[i].flow;
if(dis[v]==-1 && flow>0)
dis[v]=dis[u]+1,q.push(v);
}
}
if(dis[t]>0) return 1;
return 0;
}
inline int find(int u,int low)
{
int i,j,v,a,flow,sum=0;
if(u==t) return low;
for(i=head[u];i;i=f[i].next)
{
v=f[i].to,flow=f[i].flow;
if(dis[v]==dis[u]+1 && flow>0 && (a=find(v,min(low-sum,flow))))
{
sum+=a;
f[i].flow-=a;
if(i&1) f[i+1].flow+=a;
else f[i-1].flow+=a;
}
}
if(!sum) dis[u]=-1;
return sum;
}
int main()
{
freopen("flyer.in","r",stdin);
freopen("flyer.out","w",stdout);
int i,j,u,v;
scanf("%d%d",&n,&m); //m个正驾驶员
s=0,t=n+1;
while(scanf("%d%d",&u,&v)!=EOF)
{
add(u,v,1);
if(!bs[u]) add(s,u,1),bs[u]=1;
if(!bt[v]) add(v,t,1),bt[v]=1;
}
while(bfs())
ans+=find(s,inf);
printf("%d\n",ans);
return 0;
}