#include <bits/stdc++.h>
using namespace std;
vector<int> adj[500001];
int dist[500001];
bool visited[500001];
int bfs(int i) {
  queue<int> q;
  q.push(i);
  visited[i] = true;
  vector<pair<int, int>> time;
  while (!q.empty()) {
    int temp = q.front();
    q.pop();
    for (int j = 0; j < adj[temp].size(); j++) {
      if (!visited[adj[temp][j]]) {
        visited[adj[temp][j]] = true;
        q.push(adj[temp][j]);
        dist[adj[temp][j]] = dist[temp] + 1;
      }
    }
    if (adj[temp].size() == 1 && temp != 1) {
      time.push_back({dist[temp], temp});
    }
  }
  sort(time.begin(), time.end());
  int maxi = time[0].first;
  time[0].second = maxi;
  for (int i = 1; i < time.size(); i++) {
    time[i].second = max(dist[time[i].second], time[i - 1].second + 1);
    maxi = max(maxi, time[i].second);
  }
  return maxi;
}
int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  int x, y;
  for (int i = 1; i <= n - 1; i++) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  visited[1] = true;
  int maxi = 0;
  for (int i = 0; i < adj[1].size(); i++) {
    int temp = bfs(adj[1][i]);
    maxi = max(maxi, temp + 1);
  }
  cout << maxi;
  return 0;
}
