#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, tempBrand, tempCanOpen, ret = 0, found;
  cin >> n;
  vector<int> bottleBrands;
  vector<int> canOpenBrand;
  for (int i = 0; i < n; i++) {
    cin >> tempBrand;
    cin >> tempCanOpen;
    bottleBrands.push_back(tempBrand);
    canOpenBrand.push_back(tempCanOpen);
  }
  for (int i = 0; i < n; i++) {
    found = false;
    for (int j = 0; j < n; j++) {
      if (canOpenBrand[j] == bottleBrands[i] && j != i) {
        found = true;
      }
    }
    if (!found) {
      ret++;
    }
  }
  cout << ret;
  return 0;
}
