#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<vector<int> > l(n, vector<int>(2));
  vector<int> l2(n);
  for (int i = 0; i < n; i++) {
    l2[i] = 0;
    for (int u = 0; u < 2; u++) cin >> l[i][u];
  }
  for (int i = 0; i < n; i++) {
    for (int u = 0; u < n; u++) {
      if (i != u && l[i][1] == l[u][0] && l2[u] == 0) l2[u] = 1;
    }
  }
  int v(0);
  for (int u = 0; u < n; u++) {
    if (l2[u] == 0) v++;
  }
  cout << v << endl;
  return 0;
}
