#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  bool opn[1001] = {};
  bool slf[1001] = {};
  int f, t;
  pair<int, int> arr[n];
  for (int i = 0; i < n; i++) {
    cin >> f >> t;
    arr[i] = {f, t};
    if (f != t)
      opn[t] = 1;
    else {
      if (slf[t])
        opn[t] = 1;
      else
        slf[t] = 1;
    }
  }
  int ans = n;
  for (int i = 0; i < n; i++) {
    if (opn[arr[i].first])
      ans--;
    else if (slf[arr[i].first]) {
      opn[arr[i].first] = 1;
    }
  }
  cout << ans << endl;
}
