#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, ans, f[N], g[N];
vector<int> e[N];
void add(int x, int y) {
  e[x].push_back(y);
  e[y].push_back(x);
}
void dfs(int x, int fa) {
  int d = e[x].size();
  for (int y : e[x])
    if (y ^ fa) {
      dfs(y, x);
      ans = max(ans, max(f[x] + g[y] + 1, g[x] + f[y] + d - 2));
      g[x] = max(g[x], f[y]);
      f[x] = max(f[x], g[y]);
    }
  ans = max(ans, ++f[x]);
  ans = max(ans, g[x] += d - 1 - (fa > 0));
  f[x] = max(f[x], g[x]);
}
int main() {
  scanf("%d", &n);
  for (int x, y; --n; add(x, y)) scanf("%d%d", &x, &y);
  dfs(1, 0);
  printf("%d\n", ans);
  return 0;
}
