#include <bits/stdc++.h>
int n, m;
int a[2000];
int b[2000];
int can[2000];
using namespace std;
int main() {
  int 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 j = 0; j < n; j++) {
      if (i != j && !can[j] && b[i] == a[j]) {
        can[j] = 1;
        c++;
      }
    }
  }
  cout << n - c << endl;
}
