#include <bits/stdc++.h>
using namespace std;
vector<int> con[100001];
int f[100001];
int g[100001];
int ans;
bool flag;
void dfs(int x, int y) {
  int i;
  f[x] = 0;
  g[x] = 0;
  for (i = 0; i < con[x].size(); i++) {
    if (con[x][i] == y) continue;
    dfs(con[x][i], x);
    if (flag) break;
    if (f[x] + 1 + g[con[x][i]] > ans) ans = f[x] + 1 + g[con[x][i]];
    if (g[x] + con[x].size() - 2 + f[con[x][i]] !=
        g[x] + int(con[x].size()) - 2 + f[con[x][i]]) {
      printf("%d %d %d %d %d\n", g[x], con[x].size(), f[con[x][i]],
             g[x] + int(con[x].size()) - 2 + f[con[x][i]],
             g[x] + con[x].size() - 2 + f[con[x][i]]);
      flag = true;
      break;
    }
    if (g[x] + con[x].size() - 2 + g[con[x][i]] !=
        g[x] + int(con[x].size()) - 2 + g[con[x][i]]) {
      printf("%d %d %d %d %d\n", g[x], con[x].size(), g[con[x][i]],
             g[x] + int(con[x].size()) - 2 + g[con[x][i]],
             g[x] + con[x].size() - 2 + g[con[x][i]]);
      flag = true;
      break;
    }
    if (g[x] + int(con[x].size()) - 2 + f[con[x][i]] > ans)
      ans = g[x] + int(con[x].size()) - 2 + f[con[x][i]];
    if (g[x] + int(con[x].size()) - 2 + g[con[x][i]] > ans)
      ans = g[x] + int(con[x].size()) - 2 + g[con[x][i]];
    if (f[x] < g[con[x][i]]) f[x] = g[con[x][i]];
    if (f[con[x][i]] > g[x]) g[x] = f[con[x][i]];
    if (g[con[x][i]] > g[x]) g[x] = g[con[x][i]];
  }
  f[x]++;
  g[x] += int(con[x].size()) - 1 - (y != 0);
  if (f[x] > ans) ans = f[x];
  if (g[x] > ans) ans = g[x];
}
int main() {
  int n, i, j;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) con[i].clear();
  for (i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    con[a].push_back(b);
    con[b].push_back(a);
  }
  ans = 0;
  flag = false;
  dfs(1, 0);
  printf("%d\n", ans);
  return 0;
}
