#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
#define MAXN 505
//模板开始
int n,k,ret;
int nx,ny,mat[MAXN][MAXN],fy[MAXN],matx[MAXN],maty[MAXN];
int path(int u)
{
int v;
for (v=1;v<=ny;v++)
if (mat[u][v] && fy[v]<0)
{
fy[v]=1;
if (maty[v]<0 || path(maty[v]))
{
matx[u]=v;
maty[v]=u;
return 1;
}
}
return 0;
}
int MaximumMatch()
{
int i;
memset(matx,-1,sizeof(matx));
memset(maty,-1,sizeof(maty));
for (i=1;i<=nx;i++)
if (matx[i]<0)
{
memset(fy,-1,sizeof(fy));
ret+=path(i);
}
return ret;
}//模板结束
int main()
{
cin>>n>>k;
nx=ny=n;
int x,y;
for(int i=1;i<=k;i++)
{
cin>>x>>y;
mat[x][y]=1;
}
MaximumMatch();
cout<<ret<<endl;
return 0;
}