#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, f = 0;
  cin >> n;
  vector<int> v(1001, 0);
  vector<int> eq(1001, 0);
  vector<int> va(1001, 0);
  vector<int> q;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if (a == b) {
      eq[a]++;
    } else {
      v[b]++;
    }
    q.push_back(a);
    va[a]++;
  }
  for (int i = 0; i < int(q.size()); i++) {
    if (v[q[i]] == 0) f++;
  }
  for (int i = 0; i < int(eq.size()); i++) {
    if (eq[i] == 1 && va[i] > 1 && v[i] == 0) {
      f = f - (va[i] - 1);
    }
    if (eq[i] > 1 && v[i] == 0) {
      f = f - va[i];
    }
  }
  cout << f << endl;
  return 0;
}
