#include <bits/stdc++.h>
const int N = 1e6 + 5, MAX = 3e7, MOD = 1e9 + 7;
using namespace std;
int n;
std::vector<int> g[N];
std::vector<int> leaves;
int ans;
void dfs(int u, int p, int d) {
  int ret = 0;
  if (((int)(g[u]).size()) == 1) leaves.push_back(d);
  for (auto v : g[u])
    if (v != p) dfs(v, u, d + 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  scanf("%d", &n);
  for (int i = 0, a, b; i < n - 1; i++)
    scanf("%d %d", &a, &b), g[a].push_back(b), g[b].push_back(a);
  for (auto v : g[1]) {
    leaves.clear();
    dfs(v, 1, 1);
    sort((leaves).begin(), (leaves).end());
    ans = max(ans, leaves[0]);
    for (int i = 1; i < ((int)(leaves).size()); i++) {
      ans = max(ans, leaves[i] = max(leaves[i], leaves[i - 1] + 1));
    }
  }
  printf("%d\n", ans);
}
