#include <bits/stdc++.h>
using namespace std;
bool search(vector<int> &opens, int brand, int idx) {
  int n = opens.size();
  for (int i = 0; i < n; i++) {
    if (i == idx) continue;
    if (opens[i] == brand) return true;
  }
  return false;
}
int main() {
  int n;
  cin >> n;
  vector<int> brand(n);
  vector<int> opens(n);
  for (int i = 0; i < n; i++) {
    cin >> brand[i];
    cin >> opens[i];
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (search(opens, brand[i], i) == false) ans++;
  }
  cout << ans << "\n";
}
