#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
void solve() {
  int n, cnt = 0;
  cin >> n;
  vector<int> self(n), other(n);
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    self[i] = a;
    other[i] = b;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i != j && self[i] == other[j]) {
        ++cnt;
        break;
      }
    }
  }
  cout << n - cnt << endl;
}
int main() {
  int t = 1;
  for (int i = 1; i <= t; ++i) {
    solve();
  }
  return 0;
}
