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