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