#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, f[100005], g[100005], ans;
vector<int> e[100005];
void dfs(int x, int fa) {
  int i;
  for (i = 0; i < e[x].size(); i++) {
    if (e[x][i] == fa) continue;
    dfs(e[x][i], x);
    ans = max(ans, f[x] + g[e[x][i]] + 1);
    ans = max(ans, g[x] + f[e[x][i]] + (int)e[x].size() - 2);
    f[x] = max(f[x], g[e[x][i]]);
    g[x] = max(g[x], f[e[x][i]]);
  }
  ans = max(ans, ++f[x]);
  ans = max(ans, g[x] += e[x].size() - 1 - (!!fa));
  f[x] = max(f[x], g[x]);
}
int main() {
  scanf("%d", &n);
  for (i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    e[x].push_back(y);
    e[y].push_back(x);
  }
  dfs(1, 0);
  cout << ans << endl;
  return 0;
}
