#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n], b[n], c = 0, vis[1001] = {0};
  for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i != j)
        if ((b[j] == a[i]) && vis[a[i]] == 0) {
          c++;
          break;
        }
    }
  }
  cout << n - c;
  return 0;
}
