#include <bits/stdc++.h>
using namespace std;
const long long N = 5e5 + 5;
const long long MOD = 1e9 + 7;
long long n, u, v, ans, depth[N];
vector<long long> arr;
vector<long long> adj[N];
void dfs(long long src, long long pr) {
  bool flg = 0;
  depth[src] = depth[pr] + 1;
  for (auto ele : adj[src]) {
    if (ele == pr) continue;
    dfs(ele, src);
    flg = 1;
  }
  if (!flg) arr.push_back(depth[src]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (long long i = 0; i < n - 1; i++) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  long long mx = 0, cur = 0;
  for (auto ele : adj[1]) {
    arr.clear();
    dfs(ele, 1);
    sort(arr.begin(), arr.end());
    cur = arr[0];
    for (long long i = 1; i < arr.size(); i++) cur = max(cur + 1, arr[i]);
    mx = max(mx, cur);
  }
  cout << mx;
}
