#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int n, ans;
vector<int> adj[N], vec;
void dfs(int u = 1, int par = -1, int d = 0) {
  for (int v : adj[u])
    if (v ^ par) {
      dfs(v, u, d + 1);
      if (u == 1) {
        sort(vec.rbegin(), vec.rend());
        for (int i = 0; i < vec.size(); i++) ans = max(ans, vec[i] + i);
        vec.clear();
      }
    }
  if (adj[u].size() == 1 && u ^ 1) vec.push_back(d);
}
int main() {
  cin >> n;
  for (int i = 0, u, v; i < n - 1; i++) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs();
  cout << ans << endl;
}
