#include <bits/stdc++.h>
using namespace std;
const int max_n = 500000;
int n;
int t[max_n];
int s[max_n];
vector<int> d;
vector<int> g[max_n];
void dfs(int u, int p, int dep) {
  if (g[u].size() == 1) {
    d.push_back(dep);
    return;
  }
  for (int v : g[u]) {
    if (v != p) {
      dfs(v, u, dep + 1);
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int ans = -1;
  for (int u : g[0]) {
    d.clear();
    dfs(u, 0, 0);
    sort(d.begin(), d.end());
    t[0] = d[0];
    ans = max(ans, t[0] + 1);
    for (int i = 1; i < d.size(); i++) {
      t[i] = max(d[i], t[i - 1] + 1);
      ans = max(ans, t[i] + 1);
    }
  }
  printf("%d\n", ans);
  return 0;
}
