#include <bits/stdc++.h>
const int N = 500500;
std::vector<int> g[N];
int d[N];
int n, maxM, maxD;
void go(int cur, int par = -1, int dist = 0) {
  if (dist > maxD) maxD = dist;
  bool f = false;
  for (auto v : g[cur])
    if (v != par) {
      go(v, cur, dist + 1);
      f = true;
    }
  if (!f) ++d[dist];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for (auto v : g[1]) {
    for (int i = 0; i <= maxD; ++i) d[i] = 0;
    maxD = 0;
    go(v, 1);
    int p = -1;
    for (int i = 0; i <= maxD; ++i)
      if (d[i] > 0) {
        if (i > p)
          p = i + d[i] - 1;
        else
          p += d[i];
      }
    if (p + 1 > maxM) maxM = p + 1;
  }
  printf("%d\n", maxM);
  return 0;
}
