#include "bits/stdc++.h"
const int N = 1010;
int n;
int a[N], fa[N], ind[N], out[N];
std::set<int> s;
int find(int x) {
return x == fa[x] ? x : fa[x] = find(fa[x]);
}
int main() {
freopen("pie.in", "r", stdin);
freopen("pie.out", "w", stdout);
std::cin >> n;
for (int i = 1; i < N; ++ i) {
fa[i] = i;
}
for (int i = 1; i <= n; ++ i) {
int u, v;
std::cin >> u >> v;
++ ind[v], ++ out[u];
s.insert(u), s.insert(v);
fa[find(u)] = find(v);
}
for (auto i : s) {
if (ind[i] > out[i]) {
a[find(i)] += ind[i] - out[i];
}
}
int res = 0;
for (auto i : s) {
if (find(i) == i) {
res += std::max(1, a[i]);
}
}
res += n;
std::cout << res << '\n';
return 0;
}