#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[1000], b[1000], c = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  for (int i = 0; i < n; i++) {
    for (int g = 0; g < n; g++) {
      if (a[i] == b[g] && g != i) {
        c++;
        break;
      }
    }
  }
  cout << n - c;
}
