#include <bits/stdc++.h>
using namespace std;
inline uint64_t in() {
  char c;
  register uint64_t n = 0;
  c = getchar();
  while (c != '-' && !(c >= '0' && c <= '9')) c = getchar();
  int s = 1;
  if (c == '-') {
    s *= -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    n = 10 * n + c - '0';
    c = getchar();
  }
  return n * s;
}
int sd(int n) {
  int s = 0;
  while (n) {
    s += n % 10;
    n /= 10;
  }
  return s;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, s = 0;
  cin >> n;
  pair<int, int> p[n];
  for (int i = 0; i < n; ++i) {
    cin >> p[i].first >> p[i].second;
  }
  for (int i = 0; i < n; ++i) {
    int c = 0;
    for (int j = 0; j < n; j++) {
      if (i != j && p[i].first == p[j].second) {
        c++;
      }
    }
    if (!c) s++;
  }
  cout << s;
}
