#include<stdio.h>
#include<string.h>
bool map[505][505];
int mark[505];
bool flag[505];
int m;
bool dfs(int x)
{
int i;
for(i=1;i<=m;i++)
{
if(map[x][i]==0||flag[i]) continue;
flag[i]=1;
if(mark[i]==0||dfs(mark[i]))
{
mark[i]=x;
return 1;
}
}
return 0;
}
int main()
{
int i,g,k;
int count;
while(scanf("%d%d",&g,&k)!=EOF)
{
m=g;
memset(map,0,sizeof(map));
for(i=0;i<k;i++)
{
int x,y;
scanf("%d%d",&x,&y);
map[x][y]=1;
}
memset(mark,0,sizeof(mark));
count=0;
for(i=1;i<=g;i++)
{
memset(flag,0,sizeof(flag));
if(dfs(i)==1) count++;
}
printf("%d\n",count);
}
}