#include <bits/stdc++.h>
using namespace std;
struct bottle {
  int a, b;
};
bottle c[1000];
int main(int argc, const char* argv[]) {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> c[i].a >> c[i].b;
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j == i) continue;
      if (c[i].a == c[j].b) {
        count++;
        break;
      }
    }
  }
  cout << n - count;
  return 0;
}
