#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, MOD = 1e9 + 7, maxn = 654321;
vector<int> s[maxn];
int n;
int re[maxn];
int c;
int ans;
void dfs(int now, int pre, int floor) {
  if (s[now].size() == 1) {
    re[c] = floor;
    c++;
  }
  for (int i = 0; i < s[now].size(); i++) {
    if (s[now][i] != pre) dfs(s[now][i], now, floor + 1);
  }
}
void show(int ii) {
  cout << "$"
       << " ";
  for (int i = 1; i <= ii; i++) cout << re[i] << " ";
  cout << endl;
}
int main() {
  scanf("%d", &n);
  int x, y;
  for (int i = 1; i < n; i++) {
    scanf("%d %d", &x, &y);
    s[x].push_back(y);
    s[y].push_back(x);
  }
  ans = 0;
  for (int i = 0; i < s[1].size(); i++) {
    c = 1;
    dfs(s[1][i], 1, 1);
    sort(re + 1, re + c);
    int res = 0, sum = 0, ret = 0;
    for (int ii = 1; ii < c; ii++) {
      if (re[ii] == re[ii - 1])
        res++;
      else {
        if (ii != 1) ret += (re[ii] - re[ii - 1] - 1);
        if (ret >= res) {
          ret = res = 0;
        } else {
          res -= ret;
          ret = 0;
        }
      }
    }
    sum = re[c - 1] + res;
    ans = max(ans, sum);
  }
  cout << ans << endl;
  return 0;
}
