#include <bits/stdc++.h>
using namespace std;
int inf = 1e9;
const int N = 5e5 + 10;
int dis[N], n;
bool vis[N];
vector<int> adj[N];
queue<int> q;
void bfs(int u) {
  dis[u] = 1;
  q.push(u);
  int dd = 0;
  while (!q.empty()) {
    int from = q.front();
    q.pop();
    dd = max(dis[from], dd);
    for (auto to : adj[from]) {
      if (!vis[to]) {
        vis[to] = 1;
        if (adj[to].size() == 1)
          dis[to] = ++dd;
        else
          dis[to] = dis[from] + 1;
        q.push(to);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int x, y, mx = 0;
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  vis[1] = 1;
  for (int i = 0; i < adj[1].size(); i++) bfs(adj[1][i]);
  for (int i = 1; i <= n; i++) mx = max(mx, dis[i]);
  cout << mx;
}
