#include <bits/stdc++.h>
using namespace std;
int main() {
  cout << setprecision(20) << fixed;
  int t = 1;
  while (t--) {
    int n;
    cin >> n;
    int a[n], b[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i] >> b[i];
    }
    int c = 0;
    for (int i = 0; i < n; i++) {
      bool ok = true;
      for (int j = 0; j < n; j++) {
        if ((i != j) && (b[j] == a[i])) ok = false;
      }
      if (ok) c++;
    }
    cout << c << endl;
  }
  return 0;
}
