#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
  int nbot, b1, b2;
  int f2 = 0;
  int ok = 0;
  int found = 0;
  int count = 0;
  int notOpen = 0;
  vector<int> v1;
  vector<int> v2;
  vector<int> v2Aux;
  scanf("%d", &nbot);
  for (int i = 0; i < nbot; ++i) {
    f2 = 0;
    scanf("%d %d", &b1, &b2);
    if (find(v2.begin(), v2.end(), b2) != v2.end()) f2 = 1;
    v1.push_back(b1);
    v2Aux.push_back(b2);
    if (f2 == 0) v2.push_back(b2);
  }
  for (int i = 0; i < nbot; ++i) {
    if (v1.at(i) == v2Aux.at(i)) {
      ok = 0;
      for (int j = 0; j < nbot; ++j) {
        if (j != i) {
          if (v1.at(i) == v2Aux.at(j)) {
            ok = 1;
            break;
          }
        }
      }
      if (ok == 0) notOpen++;
    }
  }
  for (int i = 0; i < v1.size(); ++i) {
    found = 0;
    for (int j = 0; j < v2.size(); ++j) {
      if (v1.at(i) == v2.at(j)) {
        found = 1;
        break;
      }
    }
    if (found == 0) count++;
  }
  count += notOpen;
  cout << count << '\n';
  return 0;
}
