#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
vector<int> g[N];
bool visited[N];
vector<int> z;
void dfs(int v, int depth) {
  visited[v] = true;
  bool isLeaf = true;
  for (auto& i : g[v]) {
    if (!visited[i]) {
      dfs(i, depth + 1);
      isLeaf = false;
    }
  }
  if (isLeaf) z.push_back(depth);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int ans = -1;
  visited[1] = true;
  for (auto& j : g[1]) {
    z.clear();
    dfs(j, 0);
    sort(z.begin(), z.end());
    int prev = z[0], cur = -1;
    for (int i = 1; i < z.size(); i++) {
      cur = max(z[i], prev + 1);
      prev = cur;
    }
    ans = max(ans, prev + 1);
  }
  printf("%d\n", ans);
}
