#include <bits/stdc++.h>
int main(int argc, char const *argv[]) {
  int n, flag = 0, count = 0;
  int a[1000], b[1000];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d %d", &a[i], &b[i]);
  for (int i = 0; i < n; i++) {
    flag = 0;
    for (int j = 0; j < n; j++) {
      if ((i != j) && (b[j] == a[i])) flag = 1;
    }
    if (flag == 0) count++;
  }
  printf("%d ", count);
  return 0;
}
