#include <bits/stdc++.h>
using namespace std;
vector<int> q[500005], v;
void dfs(int cur, int par, int j) {
  int k = 0;
  for (int i = 0; i < q[cur].size(); i++) {
    if (q[cur][i] == par) continue;
    k = 1;
    dfs(q[cur][i], cur, j + 1);
  }
  if (k == 0) v.push_back(j);
}
int main() {
  int n, i, j, k, ans;
  scanf("%d", &n);
  for (i = 1; i < n; i++) {
    scanf("%d", &j);
    scanf("%d", &k);
    q[j].push_back(k);
    q[k].push_back(j);
  }
  ans = 0;
  for (i = 0; i < q[1].size(); i++) {
    v.clear();
    dfs(q[1][i], 1, 1);
    sort(v.begin(), v.end());
    j = v.size();
    for (k = 0; k < j; k++) ans = max(ans, v[k] + j - k - 1);
  }
  printf("%d\n", ans);
  return 0;
}
