#include <bits/stdc++.h>
using namespace std;
vector<int> G[500005];
vector<int> v;
int ans;
void dfs(int n, int p, int dist) {
  if (n == 1) {
    for (auto &z : G[n]) {
      if (z != p) {
        dfs(z, n, dist + 1);
        sort(v.begin(), v.end());
        int free = 1, time = 0;
        for (auto &z : v) {
          if (z >= free) {
            free = z + 1;
            time = z;
          } else {
            time = free;
            free++;
          }
        }
        ans = max(ans, time);
        v.clear();
      }
    }
  } else {
    if ((int)((G[n]).size()) == 1) {
      v.push_back(dist);
      return;
    }
    for (auto &z : G[n]) {
      if (z != p) {
        dfs(z, n, dist + 1);
      }
    }
  }
}
int main() {
  int n, i, j, t;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(1, -1, 0);
  cout << ans;
  return 0;
}
