#include <bits/stdc++.h>
using namespace std;
vector<int> tree[500001];
bool intree[500001];
vector<int> tmp(0);
bool isleaf(int node) {
  if (tree[node].size() == 1 && intree[(tree[node])[0]]) return true;
  return false;
}
void DFS(int lvl, int node) {
  intree[node] = true;
  if (isleaf(node)) {
    tmp.push_back(lvl);
  }
  for (int i = 0; i < tree[node].size(); i++) {
    if (!intree[(tree[node])[i]]) {
      DFS(lvl + 1, (tree[node])[i]);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  int N;
  cin >> N;
  for (int i = 1; i <= N; i++) intree[i] = false;
  int x, y;
  for (int i = 0; i < N - 1; i++) {
    cin >> x >> y;
    tree[x].push_back(y);
    tree[y].push_back(x);
  }
  intree[1] = true;
  int ans = 0, c;
  for (int i = 0; i < (tree[1]).size(); i++) {
    tmp.clear();
    DFS(0, (tree[1])[i]);
    sort(tmp.begin(), tmp.end());
    c = tmp.size();
    for (int j = 0; j < c; j++) {
      ans = max(ans, tmp[j] + c - j);
    }
  }
  cout << ans << endl;
}
