#include <bits/stdc++.h>
using namespace std;
long long n, m, c, x, y;
vector<pair<int, int> > v;
int a[10000];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    v.push_back({x, y});
    a[y] += 1;
  }
  for (int i = 0; i < n; i++) {
    x = v[i].first;
    y = v[i].second;
    if ((x == y && a[y] == 1) || (x != y && a[x] < 1)) {
      c++;
    }
  }
  cout << c;
  return 0;
}
