#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 4e7;
int head[maxn], tot, n, match[maxn], vis[maxn], cnt;
struct Edge {
int v, to;
} e[maxn];
void addedge(int u, int v) {
e[++tot] = {v, head[u]};
head[u] = tot;
}
bool dfs(int u) {
for (int p = head[u]; p; p = e[p].to) {
int v = e[p].v;
if (vis[v]) continue;
vis[v] = true;
if (!match[v] || dfs(match[v])) {
match[v] = u;
return true;
}
}
return false;
}
signed main() {
cin >> n;
for (int i = 1, v1, v2 ; i <= n; i++) {
cin >> v1 >> v2;
addedge(v1, i);
addedge(v2, i);
}
for (int i = 1; i <= n; i++) {
if (!dfs(i)) {
cout << i - 1 << endl;
return 0;
}
}
cout << n << endl;
return 0;
}