#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = (int)5e5 + 100;
const int M = (int)2e6 + 100;
const int inf = (int)1e9 + 100;
set<int> v[N][2];
int D[N];
pair<int, int> ma1[N][2];
pair<int, int> ma2[N][2];
pair<int, int> ma3[N][2];
void get(int x, int z, pair<int, int> ma4) {
  if (ma4 > ma1[x][z]) {
    ma3[x][z] = ma2[x][z];
    ma2[x][z] = ma1[x][z];
    ma1[x][z] = ma4;
  } else {
    if (ma4 > ma2[x][z]) {
      ma3[x][z] = ma2[x][z];
      ma2[x][z] = ma4;
    } else {
      if (ma4 > ma3[x][z]) {
        ma3[x][z] = ma4;
      }
    }
  }
}
int f(int x, int z, int pr = -1) {
  int o = 0;
  int d = D[x] - (pr != -1);
  while (1) {
    if (!v[x][z].size()) break;
    auto y = *v[x][z].begin();
    if (y == pr) {
      if (v[x][z].size() == 1) break;
      y = *(--v[x][z].end());
    }
    int c = f(y, 1 - z, x);
    get(x, z, {c, y});
    if (z) {
      c = f(y, z, x);
      get(x, z, {c, y});
    }
    v[x][z].erase(y);
  }
  int ma = 0;
  if (ma1[x][z].second != pr) {
    ma = ma1[x][z].first;
  } else {
    if (ma2[x][z].second != pr) {
      ma = ma2[x][z].first;
    } else {
      ma = ma3[x][z].first;
    }
  }
  if (!z)
    o = ma + 1;
  else
    o = max(d - 1 + ma, 0);
  return o;
}
int main() {
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  srand(time(0));
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, i, a, b;
  cin >> n;
  for ((i) = 0; (i) < (n - 1); (i)++) {
    cin >> a >> b;
    a--;
    b--;
    v[a][0].insert(b);
    v[b][0].insert(a);
    v[a][1].insert(b);
    v[b][1].insert(a);
    D[a]++;
    D[b]++;
  }
  int ans = 0;
  for ((i) = 0; (i) < (n); (i)++) {
    ans = max(ans, f(i, 0, -1));
  }
  cout << ans;
}
