#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n], b[n], cnt[1001] = {0};
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    cnt[b[i]]++;
  }
  int cannotopen = 0;
  for (int i = 0; i < n; i++) {
    if (cnt[a[i]] < 1 || (cnt[a[i]] == 1 && a[i] == b[i])) cannotopen++;
  }
  cout << cannotopen;
}
