//meek
///#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <sstream>
#include <vector>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define fi first
#define se second
#define MP make_pair
inline ll read()
{
ll x=0,f=1;
char ch=getchar();
while(ch<‘0‘||ch>‘9‘)
{
if(ch==‘-‘)f=-1;
ch=getchar();
}
while(ch>=‘0‘&&ch<=‘9‘)
{
x=x*10+ch-‘0‘;
ch=getchar();
}
return x*f;
}
//****************************************
const int N=250000+100;
const ll INF = 1ll<<61;
const int inf = 1<<31;
const int mod= 1000000007;
int y[501],g[101][101],lk[501],n,m,ans,gg[221][202];
int dfs(int v) {
for(int i=1;i<=n;i++) {
if(g[v][i]&&!y[i]) {
y[i]=1;
if(lk[i]==0||dfs(lk[i])) {
lk[i]=v;
return 1;
}
}
}
return 0;
}
void solve() {
mem(gg);
ans=0;
for(int i=1;i<=n;i++) {
mem(y);
ans+=dfs(i);
}
printf("%d\n",n-ans);
}
int main() {
n=read(),m=read();
int a,b;
for(int i=1;i<=m;i++) {
scanf("%d%d",&a,&b);
g[a][b]=1;
}
for(int k=1;k<=n;k++) {
for(int i=1;i<=n;i++) {
for(int j=1;j<=n;j++) {
g[i][j]=(g[i][k]&&g[k][j])||g[i][j];
}
}
}
solve();
return 0;
}