#include <bits/stdc++.h>
using namespace std;
template <typename A>
ostream &operator<<(ostream &cout, vector<A> const &v);
template <typename A, typename B>
ostream &operator<<(ostream &cout, pair<A, B> const &p) {
  return cout << "(" << p.first << ", " << p.second << ")";
}
template <typename A>
ostream &operator<<(ostream &cout, vector<A> const &v) {
  for (int i = 0; i < v.size(); i++) {
    if (i) cout << " ";
    cout << v[i];
  }
  return cout << "";
}
template <typename A, typename B>
istream &operator>>(istream &cin, pair<A, B> &p) {
  cin >> p.first;
  return cin >> p.second;
}
template <typename A>
istream &operator>>(istream &cin, vector<A> &v) {
  for (auto &i : v) cin >> i;
  return cin;
}
void solve() {
  int n, i;
  cin >> n;
  vector<pair<int, int> > arr(n);
  for (auto &x : arr) cin >> x;
  int j, ans = n;
  for (i = 0; i < n; i++) {
    auto [u, v] = arr[i];
    for (j = 0; j < n; j++) {
      if (i == j) continue;
      auto [x, y] = arr[j];
      if (y == u) {
        ans--;
        break;
      }
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
}
