#include <bits/stdc++.h>
int main() {
  int n, next = 0;
  scanf("%d", &n);
  int a[n], b[n];
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &a[i], &b[i]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (a[j] == b[i] && j != i) {
        next++;
        a[j] = 0;
      }
    }
  }
  printf("%d", n - next);
  return 0;
}
