#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const double eps = 1e-6;
const int M = 1100;
int ok[1200];
int num[1200];
int solve[1200];
vector<pair<int, int> > v;
int main() {
  memset(ok, 0, sizeof(ok));
  memset(num, 0, sizeof(num));
  memset(solve, 0, sizeof(solve));
  int n, a, b, x, y;
  cin >> n;
  for (int i = 0; i < (n); ++i) {
    cin >> a >> b;
    v.push_back(make_pair(a, b));
    num[a]++;
    if (a == b) {
      solve[a]++;
    }
  }
  int ans = 0, t;
  for (int i = 0; i < (n); ++i) {
    x = v[i].first;
    y = v[i].second;
    if (x == y) {
      t = ok[x];
      if (solve[x] >= 2)
        ok[x] = num[x];
      else if (solve[x] == 0)
        ok[x] = 0;
      else if (solve[x] == 1)
        ok[x] = num[x] - 1;
      ok[x] = max(t, ok[x]);
    } else if (x != y) {
      t = ok[y];
      ok[y] = num[y];
      ok[y] = max(t, ok[y]);
    }
  }
  for (int i = 0; i < (M); ++i) {
    ans += num[i] - ok[i];
  }
  cout << ans << endl;
  return 0;
}
