#include <bits/stdc++.h>
using namespace std;
const int Maxn = 500 * 1000 + 10;
int n, h[Maxn], ans;
vector<int> adj[Maxn], vec;
bool mark[Maxn];
void dfs(int v) {
  mark[v] = true;
  if ((int)adj[v].size() == 1) vec.push_back(h[v]);
  for (int i = 0; i < (int)adj[v].size(); i++)
    if (!mark[adj[v][i]]) {
      h[adj[v][i]] = h[v] + 1;
      dfs(adj[v][i]);
    }
  return;
}
int main() {
  scanf("%d", &n);
  int u, v;
  for (int i = 0; i < n - 1; i++) {
    scanf("%d%d", &u, &v);
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  mark[0] = true;
  for (int i = 0; i < (int)adj[0].size(); i++) {
    dfs(adj[0][i]);
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());
    int cnt = 1;
    for (int j = 0; j < (int)vec.size(); j++) {
      if (vec[j] + cnt > ans) ans = vec[j] + cnt;
      cnt++;
    }
    vec.clear();
  }
  printf("%d\n", ans);
  return 0;
}
