#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, count = 0, n;
  cin >> n;
  vector<pair<int, int>> A(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i].first >> A[i].second;
  }
  vector<int> C(10001, 0);
  for (int i = 0; i < n; i++) {
    if (A[i].first != A[i].second)
      C[A[i].second] = 1;
    else {
      if (C[A[i].first] == 2)
        C[A[i].first] = 1;
      else if (C[A[i].first] == 0)
        C[A[i].first] = 2;
    }
  }
  for (int i = 0; i < n; i++) {
    if (C[A[i].first] == 0 ||
        (C[A[i].first] == 2 && A[i].first == A[i].second)) {
      count++;
    }
  }
  cout << count;
  return 0;
}
