#include <bits/stdc++.h>
using namespace std;
int arr[500009];
int sz = 0;
vector<int> v[500009];
int n = 0;
void dfs(int nd, int pa, int lv) {
  if (int(v[nd].size()) == 1) {
    arr[sz++] = lv;
    return;
  }
  for (int i = 0; i < int(v[nd].size()); i++)
    if (v[nd][i] != pa) dfs(v[nd][i], nd, lv + 1);
}
int gor(int nd) {
  sz = 0;
  int ma = 0;
  dfs(nd, 1, 1);
  sort(arr, arr + sz);
  reverse(arr, arr + sz);
  for (int i = 0; i < sz; i++) ma = max(ma, arr[i] + i);
  return ma;
}
int main() {
  scanf("%d\n", &n);
  int a, b;
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &a, &b);
    v[a].push_back(b);
    v[b].push_back(a);
  }
  int szi = v[1].size();
  int ans = 0;
  for (int i = 0; i < szi; i++) ans = max(gor(v[1][i]), ans);
  printf("%d\n", ans);
  return 0;
}
