#include <bits/stdc++.h>
using namespace std;
int main() {
  int brandA[1000], brandB[1000], n, counter, index;
  bool found;
  while (cin >> n) {
    found = counter = 0;
    for (int i = 0; i < n; i++) cin >> brandA[i] >> brandB[i];
    for (int i = 0; i < n; i++) {
      if (brandA[i] == brandB[i])
        index = i;
      else
        index = -1;
      for (int j = 0; j < n; j++) {
        if (brandA[i] == brandB[j] && index != j) {
          found = true;
          break;
        }
      }
      if (!found) counter++;
      found = false;
    }
    cout << counter << endl;
  }
  return 0;
}
