#include <bits/stdc++.h>
using std::max;
const int MAXN = 5e5 + 5;
int n, d[MAXN], res;
std::vector<int> g[MAXN], l;
void Dfs(int u, int p) {
  d[u] = d[p] + 1;
  if (static_cast<int>(g[u].size()) == 1) l.push_back(u);
  for (int i = 0; i < static_cast<int>(g[u].size()); ++i) {
    int v = g[u][i];
    if (v != p) Dfs(v, u);
  }
}
bool comp(int a, int b) { return d[a] < d[b]; }
int SolveSubTree(int u) {
  int re = 0;
  l.clear();
  Dfs(u, 0);
  std::sort(l.begin(), l.end(), comp);
  for (int i = 0; i < static_cast<int>(l.size()); ++i)
    re = max(re + 1, d[l[i]]);
  return re;
}
void Solve() {
  for (int i = 0; i < static_cast<int>(g[0].size()); ++i)
    res = max(res, SolveSubTree(g[0][i]));
  printf("%d", res);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u - 1].push_back(v - 1);
    g[v - 1].push_back(u - 1);
  }
  Solve();
  return 0;
}
