#include <bits/stdc++.h>
using namespace std;
const long double E = 2.71828182845904523536;
const long double pi = acos(-1);
const double eps = 1e-9;
const long long mod = 1e9 + 7;
const long long inf = 1LL << 30;
const int N = 500500;
vector<int> adj[N];
vector<int> v;
int dep[N];
void DFS(int u, int p) {
  dep[u] = 1 + dep[p];
  for (auto v : adj[u])
    if (v != p) DFS(v, u);
  if (adj[u].size() == 1) v.push_back(dep[u]);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dep[1] = 0;
  int ans = 0;
  for (auto u : adj[1]) {
    v.clear();
    DFS(u, 1);
    sort(v.begin(), v.end());
    for (int i = 1; i < v.size(); i++)
      if (v[i] <= v[i - 1]) v[i] = v[i - 1] + 1;
    ans = max(ans, v.back());
  }
  printf("%d", ans);
  return 0;
}
