#include <bits/stdc++.h>
using namespace std;
const int ms = 5e5 + 5;
vector<int> g[ms];
int lvl[ms];
vector<vector<int>> leafs(ms, vector<int>());
int idx[ms];
void dfs(int v = 0, int p = 0) {
  if (v) lvl[v] = lvl[p] + 1;
  for (auto u : g[v]) {
    if (u == p) continue;
    dfs(u, v);
    if ((int)leafs[idx[u]].size() > (int)leafs[idx[v]].size())
      swap(idx[u], idx[v]);
    leafs[idx[v]].insert(leafs[idx[v]].end(), leafs[idx[u]].begin(),
                         leafs[idx[u]].end());
  }
  if (leafs[idx[v]].size() == 0) {
    leafs[idx[v]].push_back(lvl[v]);
    return;
  }
  if (lvl[v] == 1) {
    sort(leafs[idx[v]].begin(), leafs[idx[v]].end());
    for (int i = 1; i < leafs[idx[v]].size(); ++i) {
      leafs[idx[v]][i] = max(leafs[idx[v]][i - 1] + 1, leafs[idx[v]][i]);
    }
  }
  return;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    idx[i] = i;
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  idx[n - 1] = n - 1;
  dfs();
  int worst = 0;
  for (int i = 0; i < leafs[idx[0]].size(); ++i) {
    worst = max(worst, leafs[idx[0]][i]);
  }
  cout << worst << '\n';
  return 0;
}
