#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  vector<pair<long long, long long>> vec(n);
  map<long long, long long> mp;
  for (long long i = 0; i < n; i++) {
    cin >> vec[i].first;
    cin >> vec[i].second;
    mp[vec[i].second]++;
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (mp[vec[i].first] == 0 ||
        ((mp[vec[i].first] == 1) && vec[i].first == vec[i].second)) {
      ans++;
    }
  }
  cout << ans;
  return 0;
}
