#include <bits/stdc++.h>
using namespace std;
bool ifprime(long long int n) {
  if (n % 2 == 0) return 0;
  for (long long int i = 3; i * i <= n; i += 2) {
    if (n % i == 0) return 0;
  }
  return 1;
}
void output_vector(const vector<int> &a) {
  for (int i = 0; i < a.size(); i++) cout << a[i] << " ";
  cout << "\n";
}
void print(const vector<pair<int, int>> &a) {
  for (auto i : a) cout << i.first << " " << i.second << "\n";
}
void solve() {
  int n, x, y;
  cin >> n;
  vector<int> a(n), b(n);
  int c = 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 (a[i] == b[j]) {
          c++;
          break;
        }
      }
    }
  }
  cout << n - c;
}
int main() { solve(); }
