#include <bits/stdc++.h>
using namespace std;
const int M = 3000 + 10;
struct EDGE {
  int u;
  int v;
} edge[M];
vector<EDGE> adj[M];
int dpchild[M];
int dpfather[M];
void dp1(int cur, int par, int del) {
  vector<EDGE>::iterator it = adj[cur].begin();
  while (it != adj[cur].end()) {
    EDGE edge = (*it);
    int u = edge.u;
    int v = edge.v;
    int child = -1;
    int dis = 0;
    if (cur == u) {
      child = v;
    } else {
      child = u;
      dis = 1;
    }
    if (child != par && child != del) {
      dp1(child, cur, del);
      dpchild[cur] = dpchild[cur] + dpchild[child] + dis;
    }
    it++;
  }
}
void dp2(int cur, int par, int del) {
  vector<EDGE>::iterator it = adj[cur].begin();
  while (it != adj[cur].end()) {
    EDGE edge = (*it);
    int u = edge.u;
    int v = edge.v;
    int dis = 0;
    int child = -1;
    if (cur == u) {
      child = v;
      dis = 1;
    } else {
      child = u;
    }
    if (child != par && child != del) {
      int dis2 = dpchild[cur] - (dpchild[child] + (1 - dis));
      dpfather[child] = dpfather[cur] + dis + dis2;
      dp2(child, cur, del);
    }
    it++;
  }
}
int ans = M;
void cal(int cur, int par, int del) {
  ans = min(ans, dpfather[cur] + dpchild[cur]);
  vector<EDGE>::iterator it = adj[cur].begin();
  while (it != adj[cur].end()) {
    EDGE edge = (*it);
    int u = edge.u;
    int v = edge.v;
    int child = -1;
    if (cur == u) {
      child = v;
    } else {
      child = u;
    }
    if (child != par && child != del) {
      cal(child, cur, del);
    }
    it++;
  }
}
void solve(int cur, int par, int del) {
  dp1(cur, par, del);
  dp2(cur, par, del);
}
int main() {
  time_t t_start, t_end;
  t_start = clock();
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    edge[i].u = a;
    edge[i].v = b;
    adj[a].push_back(edge[i]);
    adj[b].push_back(edge[i]);
  }
  int res = M;
  for (int i = 0; i < n - 1; i++) {
    for (int j = 0; j < M; j++) {
      dpchild[j] = dpfather[j] = 0;
    }
    int u = edge[i].u;
    int v = edge[i].v;
    solve(u, 0, v);
    solve(v, 0, u);
    ans = M;
    cal(u, 0, v);
    int tmp = ans;
    ans = M;
    cal(v, 0, u);
    tmp += ans;
    res = min(res, tmp);
  }
  if (n == 1) {
    res = 0;
  }
  cout << res << endl;
  t_end = clock();
  return 0;
}
