#include <bits/stdc++.h>
using namespace std;
const int N = (int)5e5 + 10;
vector<int> graph[N];
vector<int> d(N);
vector<int> w;
void dfs(int v, int pred) {
  d[v] = d[pred] + 1;
  if (graph[v].size() == 1) {
    w.push_back(d[v]);
  }
  for (int i = 0; i < graph[v].size(); ++i) {
    int to = graph[v][i];
    if (to != pred) dfs(to, v);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--, v--;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  int ans = 0;
  for (int i = 0; i < graph[0].size(); ++i) {
    dfs(graph[0][i], 0);
    sort(w.begin(), w.end());
    int cur = 0;
    for (int j = 0; j < w.size(); ++j) {
      if (w[j] > cur) cur = w[j];
      cur++;
    }
    ans = max(ans, cur - 1);
    w.resize(0);
  }
  printf("%d", ans);
}
