#include <bits/stdc++.h>
using namespace std;
vector<long long> g[511111];
bool u[511111];
void dfs(long long i, long long h, vector<pair<long long, long long> > &v) {
  u[i] = true;
  if (g[i].size() == 1) v.push_back(make_pair(h, i));
  h++;
  for (long long jj = 0; jj < (long long)(g[i].size()); jj++) {
    long long j = g[i][jj];
    if (u[j]) continue;
    dfs(j, h, v);
  }
}
int main(void) {
  long long n;
  cin >> n;
  for (long long i = 0; i < (long long)(n - 1); i++) {
    long long a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  long long ans = 0;
  u[0] = true;
  for (long long jj = 0; jj < (long long)(g[0].size()); jj++) {
    long long j = g[0][jj];
    vector<pair<long long, long long> > v;
    dfs(j, 1, v);
    sort(v.begin(), v.end());
    long long t = 0;
    for (long long ii = 0; ii < (long long)(v.size()); ii++) {
      long long h = v[ii].first;
      t = max(t + 1, h);
      ans = max(ans, t);
    }
  }
  cout << ans << '\n';
  return 0;
}
