#include
#include
#include
#include
#include
using namespace std;
typedef long long ll;
const int maxn = 667;
bool graph[maxn][maxn];
bool visited[maxn];
int match[maxn];
int n, k;
bool dfs(int node) {
for(int i = 0; i < n; i++) {
if(graph[node][i] and !visited[i]) {
visited[i] = true;
if(match[i] == -1 or dfs(match[i])) {
match[i] = node;
return true;
}
}
}
return false;
}
int maximum_bipartite_matching() {
memset(match, -1, sizeof match);
int result = 0;
for(int i = 0; i < n; i++) {
memset(visited, false, sizeof visited);
if(dfs(i)) {
result++;
}
}
return result;
}
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> k;
memset(graph, true, sizeof graph);
for(int i = 0; i < k; i++) {
int a, b;
cin >> a >> b;
a--; b--;
graph[a][b] = false;
}
cout << maximum_bipartite_matching() << endl;
return 0;
}