#include <bits/stdc++.h>
using namespace std;
struct node {
  int a, b;
  bool sts;
};
int main() {
  int n;
  cin >> n;
  node no[n];
  for (int i = 0; i < n; i++) {
    cin >> no[i].a >> no[i].b;
    no[i].sts = true;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i != j) {
        if (no[i].b == no[j].a) no[j].sts = false;
      }
    }
  }
  int cnt = 0;
  for (int i = 0; i < n; i++)
    if (no[i].sts) cnt++;
  cout << cnt << "\n";
  return 0;
}
