#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, n, ans = 0;
  cin >> n;
  vector<int> b2(1000);
  vector<int> bad(1000);
  vector<int> b1(1000);
  for (int i = 0; i < 1000; i++) {
    b2[i] = 0;
    bad[i] = 0;
    b1[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    b2[a - 1]++;
    if (a == b) bad[a - 1]++;
    b1[b - 1]++;
  }
  for (int i = 0; i < 1000; i++) {
    if (b1[i] == 0) ans += b2[i];
    if (b1[i] == 1 && bad[i] == 1) ans++;
  }
  cout << ans << endl;
}
