#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, br = 0, a, b;
  cin >> n;
  vector<int> v1(n);
  vector<int> v2(n);
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    v1[i] = a;
    v2[i] = b;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++)
      if (v1[i] == v2[j] && i != j) {
        br++;
        break;
      }
  }
  cout << n - br;
}
