#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int total(n);
  int A[n];
  int B[n];
  for (int i = 0; i < n; i++) {
    cin >> A[i] >> B[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) {
        continue;
      }
      if (A[i] == B[j]) {
        total--;
        A[i] = 0;
      }
    }
  }
  cout << total;
}
