#include <bits/stdc++.h>
using namespace std;
int main() {
  int x;
  while (cin >> x) {
    int num;
    vector<int> v1, v2;
    int sum = 0;
    for (int i = 0; i < x; i++) {
      cin >> num;
      v1.push_back(num);
      cin >> num;
      v2.push_back(num);
    }
    for (int i = 0; i < x; i++) {
      for (int m = 0; m < x; m++) {
        if (v1[m] == v2[i] && i != m) {
          sum++;
          v1[m] = 0;
        }
      }
    }
    cout << x - sum << endl;
  }
}
