#include <bits/stdc++.h>
using namespace std;
template <typename T, typename TT>
ostream& operator<<(ostream& os, const pair<T, TT>& t) {
  return os << t.first << " " << t.second;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& t) {
  for (auto& i : t) os << i << " ";
  return os;
}
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
int main() {
  long long n, a, b;
  scanf("%lld", &n);
  vector<pair<long long, long long>> v;
  unordered_map<int, int, custom_hash> c, o;
  for (long long i = 0; i < n; i++) {
    scanf("%lld %lld", &a, &b);
    v.push_back(make_pair(a, b));
    c[a]++;
    o[b]++;
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if (v[i].first == v[i].second) {
      if (c[v[i].second] > 1 && o[v[i].second] > 1) {
        ans += c[v[i].first];
        c[v[i].first] = 0;
      } else if (c[v[i].second] > 1 && o[v[i].second] == 1) {
        ans = ans + c[v[i].first] - 1;
        c[v[i].first] = 1;
      }
    } else {
      ans += c[v[i].second];
      c[v[i].second] = 0;
    }
  }
  cout << n - ans;
  return 0;
}
