#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, o = 0, a, b;
  cin >> n;
  bool opened[1001] = {false};
  int count[1001] = {0};
  int opener[1001] = {0};
  vector<pair<int, int>> v;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    v.push_back(make_pair(a, b));
    count[a]++;
    opener[b]++;
  }
  for (int i = 0; i < n; i++) {
    if (v[i].first == v[i].second && count[v[i].first] &&
        opener[v[i].first] == 1)
      count[v[i].first] = 1;
    else
      count[v[i].second] = 0;
  }
  for (int i = 1; i <= 1000; i++) o += count[i];
  cout << o;
  return 0;
}
