#include <bits/stdc++.h>
using namespace std;
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
void debugarr(int* arr, int n) {
  cout << "[";
  for (int i = 0; i < n; i++) cout << arr[i] << " ";
  cout << "]" << endl;
}
template <class T>
inline void checkMin(T& a, const T b) {
  if (b < a) a = b;
}
template <class T>
inline void checkMax(T& a, const T b) {
  if (a < b) a = b;
}
template <class T>
inline T min(T a, T b, T c) {
  return min(min(a, b), c);
}
template <class T>
inline T max(T a, T b, T c) {
  return max(max(a, b), c);
}
template <class T>
inline T min(T a, T b, T c, T d) {
  return min(min(a, b), min(c, d));
}
template <class T>
inline T max(T a, T b, T c, T d) {
  return max(max(a, b), max(c, d));
}
inline int ceil(int x, int y) { return (x - 1) / y + 1; }
int main() {
  vector<int> a, b;
  int bottles;
  cin >> bottles;
  for (int i = 0; i < bottles; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    a.push_back(x);
    b.push_back(y);
  }
  int opened = 0;
  for (int i = 0; i < bottles; i++) {
    int ok = false;
    for (int j = 0; j < bottles; j++) {
      if (i != j && a[i] == b[j]) ok = true;
    }
    if (ok) opened++;
  }
  cout << bottles - opened << endl;
  return 0;
}
