#include <bits/stdc++.h>
using namespace std;
int sett(int N, int pos) { return N = N | (1 << pos); }
int reset(int N, int pos) { return N = N & ~(1 << pos); }
bool check(int N, int pos) { return (bool)(N & (1 << pos)); }
void update(long long &x, long long val) {
  x = x + val;
  if (x > 1000000007) x -= 1000000007;
}
void fast() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL), cout.tie(NULL);
}
int is_prime(long long n) {
  if (n == 2) return 1;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return 0;
  }
  return 1;
}
vector<int> graph[1000100];
int tot = 0;
int vis[1001000] = {};
vector<int> temp;
int dis[1001000] = {};
void dfs(int node) {
  vis[node] = 1;
  int loop = graph[node].size();
  if (loop == 1) {
    temp.push_back(dis[node]);
    return;
  }
  for (int i = 0; i < loop; i++) {
    int next = graph[node][i];
    if (!vis[next]) {
      dis[next] = dis[node] + 1;
      dfs(next);
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    int p, q;
    scanf("%d%d", &p, &q);
    graph[p].push_back(q);
    graph[q].push_back(p);
  }
  int mx = 0;
  int loop = graph[1].size();
  vis[1] = 1;
  dis[1] = 0;
  for (int i = 0; i < loop; i++) {
    vis[graph[1][i]] = 1;
    int node_from = graph[1][i];
    dis[node_from] = 1;
    temp.clear();
    dfs(graph[1][i]);
    sort(temp.begin(), temp.end());
    tot = temp[0];
    for (int i = 1; i < temp.size(); i++) {
      tot = max(tot + 1, temp[i]);
    }
    mx = max(mx, tot);
  }
  cout << mx;
  return 0;
}
