#include <bits/stdc++.h>
using namespace std;
int ar[1001][2];
int lol[10001];
int main() {
  int n;
  cin >> n;
  int a, b;
  int i;
  for (i = 0; i < n; i++) {
    cin >> ar[i][0] >> ar[i][1];
  }
  int j, k;
  for (j = 0; j < n; j++) {
    for (k = 0; k < n; k++) {
      if (j != k && ar[j][1] == ar[k][0]) {
        lol[k] = 1;
      }
    }
  }
  int ans = 0;
  for (i = 0; i < n; i++) {
    if (lol[i] == 0) {
      ans++;
    }
  }
  cout << ans << endl;
}
