#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10, mod = 1e9 + 7;
vector<int> g[N];
int cnt[N], t;
void dfs(int v, int p, int h) {
  t++;
  if (g[v].size() == 1 && v != 0) {
    cnt[h]++;
  }
  for (int u : g[v]) {
    if (u != p) {
      dfs(u, v, h + 1);
    }
  }
}
void solve() {
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int ans = 0;
  for (int v : g[0]) {
    t = 0;
    dfs(v, 0, 1);
    for (int i = 1; i <= t; i++) {
      cnt[i] += cnt[i - 1];
      if (cnt[i] > 0) {
        cnt[i]--;
        ans = max(ans, i + cnt[i]);
      }
    }
    for (int i = 1; i <= t; i++) {
      cnt[i] = 0;
    }
  }
  cout << ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
