#include <bits/stdc++.h>
using namespace std;
vector<vector<long long int> > subtrleafs;
vector<long long int> leafs;
void dfs(int u, int p, vector<vector<long long int> > &g,
         vector<long long int> &vis) {
  if (p != -1) vis[u] = vis[p] + 1;
  bool leaf = true;
  for (auto &z : g[u]) {
    if (u == 0) {
      leafs.clear();
    }
    if (!vis[z] and z != p) {
      leaf = false;
      dfs(z, u, g, vis);
      if (u == 0) {
        subtrleafs.push_back(leafs);
      }
    }
  }
  if (leaf) {
    leafs.push_back(vis[u]);
  }
  return;
}
int main() {
  long long int tt = 1, n, m, k = 0, i, j, p, q;
  long long int a, b, c, d, u, v, x, y;
  long long int ans = 0;
  long long int l = 0, r = 0;
  bool poss = true;
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  string s, t;
  for (int _ = 1; _ <= tt; _++) {
    cin >> n;
    vector<vector<long long int> > g(n);
    for (i = 0; i < n - 1; i++) {
      cin >> x >> y;
      x--, y--;
      g[x].push_back(y);
      g[y].push_back(x);
    }
    vector<long long int> vis(n, 0);
    vis[0] = 1;
    dfs(0, -1, g, vis);
    ans = 0;
    for (auto &z : subtrleafs) {
      sort(z.begin(), z.end());
      long long int t = 0;
      for (i = 1; i < (long long int)(z).size(); i++) {
        if (z[i] == z[i - 1]) {
          t++;
        } else {
          t = max(0LL, t - z[i] + z[i - 1] + 1);
        }
      }
      ans = max(ans, t + z.back() - 1);
    }
    cout << ans << "\n";
  }
  return 0;
}
