#include <bits/stdc++.h>
using namespace std;
char _;
const int maxN = 500 * 1000 + 15;
const int maxM = 100 * 100 + 5;
const int mod = 1000 * 1000 * 1000 + 7;
const int base = 701;
const int SQ = 500;
const int maxL = 17;
vector<int> a[maxN];
int dis[maxN];
int mx;
void dfs(int v, int h, int par) {
  for (auto u : a[v])
    if (u - par) dfs(u, h + 1, v);
  if ((int)a[v].size() == 1) dis[h]++, mx = max(mx, h);
}
int32_t main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int v, u;
    scanf("%d%d", &v, &u);
    v--;
    u--;
    a[v].push_back(u);
    a[u].push_back(v);
  }
  int ans = 0;
  for (auto v : a[0]) {
    mx = 0;
    dfs(v, 1, 0);
    int bes = 0, rem = 0;
    for (int i = 0; i < mx + 1; i++) {
      if (dis[i]) bes = max(bes, i + rem + (dis[i] - 1));
      rem += dis[i];
      if (rem) rem--;
      dis[i] = 0;
    }
    ans = max(ans, bes);
  }
  cout << ans << endl;
  return 0;
}
