#include <bits/stdc++.h>
using namespace std;
vector<int> adjList[500010];
struct data {
  set<int> *slots, *ants;
  int offset;
  int st, ed;
};
data dfs(int u, int p) {
  data ret;
  vector<data> kids;
  for (auto v : adjList[u]) {
    if (v == p) continue;
    kids.push_back(dfs(v, u));
  }
  if (kids.size() == 0) {
    ret.slots = new set<int>();
    ret.ants = new set<int>();
    ret.ants->insert(0);
    ret.st = ret.ed = ret.offset = 0;
    return ret;
  }
  int maxidx = 0;
  for (int i = 0; i < kids.size(); i++)
    if (kids[i].ants->size() > kids[maxidx].ants->size()) maxidx = i;
  ret = kids[maxidx];
  ret.offset += 1;
  for (int i = 0; i < kids.size(); i++) {
    if (i == maxidx) continue;
    kids[i].offset += 1;
    for (auto itr = kids[i].ants->begin(); itr != kids[i].ants->end(); itr++) {
      int x = *itr;
      x += kids[i].offset - ret.offset;
      while (x < ret.st) {
        ret.st -= 1;
        ret.slots->insert(ret.st);
      }
      while (x > ret.ed) {
        ret.ed += 1;
        ret.slots->insert(ret.ed);
      }
      auto it = ret.slots->lower_bound(x);
      if (it == ret.slots->end()) {
        ret.ed += 1;
        ret.ants->insert(ret.ed);
      } else {
        ret.ants->insert(*it);
        ret.slots->erase(it);
      }
    }
  }
  return ret;
}
int main() {
  int N;
  scanf("%d", &N);
  for (int i = 0; i < N - 1; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--;
    v--;
    adjList[u].push_back(v);
    adjList[v].push_back(u);
  }
  int maxtime = 0;
  for (auto v : adjList[0]) {
    data ret = dfs(v, 0);
    auto it = --ret.ants->end();
    maxtime = max(maxtime, (*it) + ret.offset);
  }
  cout << maxtime + 1 << endl;
  return 0;
}
