#include <bits/stdc++.h>
using namespace std;
const int N = (int)5e5 + 7;
vector<int> v[N];
vector<int> levels;
int n, foo, bar;
int dep[N];
void dfs(int x, int w) {
  dep[x] = dep[w] + 1;
  bool isleaf = true;
  for (auto y : v[x]) {
    if (y != w) {
      dfs(y, x);
      isleaf = false;
    }
  }
  if (isleaf) {
    levels.push_back(dep[x]);
  }
}
int main() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &foo, &bar);
    v[foo].push_back(bar);
    v[bar].push_back(foo);
  }
  int ans = 0;
  for (int i = 0; i < v[1].size(); i++) {
    levels.clear();
    dfs(v[1][i], 1);
    sort(levels.begin(), levels.end());
    int now = 0;
    for (auto y : levels) {
      if (y > now)
        now = y;
      else
        now++;
    }
    ans = max(ans, now);
  }
  cout << ans << "\n";
  return 0;
}
