#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
pair<int, int> arr[MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> arr[i].first >> arr[i].second;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    bool ok = false;
    for (int j = 0; j < n; j++)
      if (i != j && arr[i].first == arr[j].second) ok = true;
    if (!ok) ++ans;
  }
  cout << ans << endl;
  return 0;
}
