#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
pair<int, int> p[maxn];
bool Open[maxn];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int fi, se;
    cin >> p[i].first >> p[i].second;
  }
  int open = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++)
      if (j != i && p[i].second == p[j].first && !Open[j]) open++, Open[j] = 1;
  }
  cout << n - open;
}
