#include <bits/stdc++.h>
using namespace std;
template <class T>
T fm(T number, T module) {
  T result = 1;
  while (number > 1) {
    result = (result * ((number / module) % 2 ? module - 1 : 1)) % module;
    for (T it = 2; it <= (number % module); ++it) {
      result = (result * it) % module;
    }
    number /= module;
  }
  return result % module;
}
int main(int argc, char *argv[]) {
  std::ios_base::sync_with_stdio(false);
  unsigned n(0), m(0);
  cin >> n;
  vector<pair<unsigned, unsigned> > array(n);
  for (unsigned it(0); it != n; ++it) {
    cin >> array[it].first >> array[it].second;
  }
  int answer(n);
  for (unsigned it(0); it != n; ++it) {
    bool open(false);
    for (unsigned il(0); il != n; ++il) {
      if (it != il) {
        if (array[it].first == array[il].second) {
          open = true;
          break;
        }
      }
    }
    if (open) {
      --answer;
    }
  }
  cout << answer;
  return 0;
}
