#include <bits/stdc++.h>
using namespace std;
vector<long long int> adj[500005];
long long int depth[500005];
vector<long long int> v;
inline void dfs(long long int x, long long int p, long long int d) {
  depth[x] = d;
  for (auto i : adj[x])
    if (i != p) dfs(i, x, d + 1);
  if (adj[x].size() == 1) v.push_back(depth[x]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int n;
  cin >> n;
  for (long long int i = 1; i < n; i++) {
    long long int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  long long int ans = 0;
  for (auto i : adj[1]) {
    v.clear();
    dfs(i, 1, 1);
    sort(v.begin(), v.end());
    for (long long int i = 1; i < v.size(); i++) v[i] = max(v[i - 1] + 1, v[i]);
    ans = max(v.back(), ans);
  }
  cout << ans;
}
