#include <bits/stdc++.h>
using namespace std;
int main(void) {
  unsigned long num_bottles = 0;
  cin >> num_bottles;
  map<unsigned long, pair<unsigned long, unsigned long> > links;
  map<unsigned long, unsigned long> counts;
  for (unsigned long n = 0; n < num_bottles; n++) {
    unsigned long a = 0, b = 0;
    cin >> a >> b;
    counts[a]++;
    links[a];
    if (a == b) {
      links[b].second++;
    } else {
      links[b].first++;
    }
  }
  unsigned long unopened = 0;
  for (map<unsigned long, pair<unsigned long, unsigned long> >::iterator
           links_it = links.begin();
       links_it != links.end(); ++links_it) {
    unsigned long bottle = links_it->first;
    unsigned long from_outside = links_it->second.first;
    unsigned long from_within = links_it->second.second;
    if (from_outside > 0) continue;
    if (from_within > 1) continue;
    if (from_within == 1) {
      unopened++;
      continue;
    }
    unopened += counts[bottle];
  }
  cout << unopened;
  return 0;
}
