#include <bits/stdc++.h>
using namespace std;
vector<int> mp[600001];
int vis[600001];
int dp[600001];
int cnt;
void dfs(int u, int t) {
  if (vis[u] == 1) return;
  vis[u] = 1;
  if (mp[u].size() == 1) dp[cnt++] = t;
  for (int i = 0; i < mp[u].size(); i++) {
    dfs(mp[u][i], t + 1);
  }
}
int main() {
  int n, u, v;
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    cin >> u >> v;
    mp[u].push_back(v);
    mp[v].push_back(u);
  }
  vis[1] = 1;
  int ans = 0;
  for (int i = 0; i < mp[1].size(); i++) {
    cnt = 0;
    dfs(mp[1][i], 1);
    sort(dp, dp + cnt);
    for (int ii = 1; ii < cnt; ii++) {
      dp[ii] = max(dp[ii], 1 + dp[ii - 1]);
    }
    ans = max(ans, dp[cnt - 1]);
  }
  cout << ans << "\n";
  return 0;
}
