#include <bits/stdc++.h>
using namespace std;
long long n;
vector<long long> g[500005];
vector<long long> temp;
void dfs(long long node, long long par, long long lev) {
  long long sz = g[node].size();
  bool flag = 1;
  for (long long i = 0; i <= sz - 1; i++) {
    long long child = g[node][i];
    if (child != par) {
      flag = 0;
      dfs(child, node, lev + 1);
    }
  }
  if (flag) temp.push_back(lev);
}
int main() {
  std::ios::sync_with_stdio(false);
  cin >> n;
  for (long long i = 1; i <= n - 1; i++) {
    long long u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  long long sz = g[1].size();
  long long ans = 0;
  for (long long i = 0; i <= sz - 1; i++) {
    temp.clear();
    long long child = g[1][i];
    dfs(child, 1, 1);
    long long s = temp.size();
    sort(temp.begin(), temp.end());
    long long prev = temp[0];
    for (long long j = 1; j <= s - 1; j++) prev = max(temp[j], prev + 1);
    ans = max(ans, prev);
  }
  cout << ans << endl;
  return 0;
}
