#include <bits/stdc++.h>
using namespace std;
vector<int> Adj[5 * 100001];
vector<int> Val[5 * 100001];
int vis[5 * 100001];
void DFS(int u, int idx, int dep) {
  vis[u] = 1;
  for (auto v : Adj[u])
    if (!vis[v]) DFS(v, idx, dep + 1);
  if (Adj[u].size() == 1) Val[idx].push_back(dep);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int N, i, l, r;
  cin >> N;
  for (i = 0; i < N - 1; ++i) {
    cin >> l >> r;
    Adj[l].push_back(r);
    Adj[r].push_back(l);
  }
  vis[1] = 1;
  int ctr = 1;
  for (auto v : Adj[1]) {
    DFS(v, ctr, 1);
    ++ctr;
  }
  int Time = 0, j;
  for (i = 1; i < ctr; ++i) {
    sort(Val[i].begin(), Val[i].end(), greater<int>());
    for (j = 0; j < (int)Val[i].size(); ++j) Time = max(Time, Val[i][j] + j);
  }
  cout << Time;
  return 0;
}
