#include <set>
#include <cstdio>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

inline int getInt(){ int s; scanf("%d", &s); return s; }

typedef long long ll;

using namespace std;

int main(){
  int n = getInt();
  vector<int> l(n - 1);
  vector<int> r(n - 1);

  vector<ll> dp1(n);
  vector<ll> dp2(n);
  vector<ll> dp(n);
  vector<ll> depth(n);

  REP(i,n - 1){
    l[i] = getInt() - 1;
    r[i] = getInt() - 1;
    depth[r[i]] = depth[i] + 1;
    depth[l[i]] = depth[i] + 1;
  }

  dp[n - 1] = dp2[n - 1] = 0;
  dp1[n - 1] = 1;

  for(int i = n - 2; i >= 0; i--){
    dp1[i] = dp1[l[i]] + dp1[r[i]];
    dp2[i] = dp2[l[i]] + dp2[r[i]] + dp1[i];

    dp[i] = min(dp[l[i]] + dp2[r[i]] + dp1[r[i]] + 1,
                dp[r[i]] + dp2[l[i]] + dp1[l[i]] + 1);
    dp[i] = min(dp[i], 1 + dp[l[i]] + depth[i] + 1 + dp[r[i]]);
  }
  // REP(i,n-1) printf("%d: dp1 = %lld  dp2 = %lld  dp = %lld\n", i, dp1[i], dp2[i], dp[i]);

  printf("%lld\n", dp[0]);

  return 0;
}