#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ","
       << " ";
  err(++it, args...);
  cout << printf("\n");
}
bool checkbit(int mask, int bit) { return mask & (1 << bit); }
int setbit(int mask, int bit) { return mask | (1 << bit); }
int clearbit(int mask, int bit) { return mask & ~(1 << bit); }
int togglebit(int mask, int bit) { return mask ^ (1 << bit); }
int bitno(int mask) { return (int)__builtin_popcount(mask); }
const int fx[] = {+1, -1, +0, +0};
const int fy[] = {+0, +0, +1, -1};
const long long maX = 1e7 + 10;
double eps = 1e-9;
int main() {
  long long n;
  scanf("%lld", &n);
  long long a[n], b[n];
  long long cc = 0;
  map<long long, long long> check, dj;
  for (long long i = 0; i < n; i++) {
    scanf("%lld %lld", &a[i], &b[i]);
    check[b[i]]++;
  }
  for (long long i = 0; i < n; i++) {
    if (check[a[i]] == 0 || (check[a[i]] == 1 && a[i] == b[i])) cc++;
  }
  cout << cc << endl;
  return 0;
}
