#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int>> bottles(n);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    bottles[i] = {a, b};
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i != j) {
        if (bottles[i].first == bottles[j].second) {
          ans++;
          break;
        }
      }
    }
  }
  cout << n - ans << endl;
  return 0;
}
