#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const long long llinf = (long long)3e18;
const int N = (int)1e5 + 111;
const long double PI = (long double)acos(-1);
int main() {
  int n, ans = 0;
  scanf("%d", &n);
  map<int, int> cnt;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &a[i], &b[i]);
    cnt[b[i]]++;
  }
  for (int i = 0; i < n; i++)
    if (cnt[a[i]] != 0 && !(cnt[a[i]] == 1 && a[i] == b[i])) ans++;
  printf("%d", n - ans);
  return 0;
}
