#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int ar[n], ar1[n];
  for (long long int i = 0; i < n; i++) cin >> ar[i] >> ar1[i];
  int s = 0;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < n; j++) {
      if (i != j) {
        if (ar[i] == ar1[j]) {
          s++;
          break;
        }
      }
    }
  }
  cout << n - s;
}
