#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n + 1], b[n + 1];
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
  }
  int counter = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (b[i] == a[j] and i != j) {
        a[j] = 0;
        counter++;
      }
    }
  }
  cout << n - counter << endl;
  return 0;
}
