#include <bits/stdc++.h>
using namespace std;
int mp[10000];
vector<pair<long long int, long long int> > vp;
int main() {
  long long int n, count = 0, x, y, i;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x >> y;
    vp.push_back(make_pair(x, y));
    mp[y]++;
  }
  for (i = 0; i < n; i++)
    if (vp[i].first != vp[i].second && mp[vp[i].first])
      count++;
    else if (vp[i].first == vp[i].second && mp[vp[i].first] > 1)
      count++;
  cout << n - count;
}
