#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
vector<int> e[N];
int n, ans, f[N][2], g[N][2];
void dfs1(int x, int fa) {
  f[x][0] = 0;
  f[x][1] = 0;
  int d = e[x].size() - (fa != 0);
  for (auto i : e[x])
    if (i != fa) {
      dfs1(i, x);
      f[x][0] = max(f[x][0], max(f[i][0], f[i][1]) - 1);
      f[x][1] = max(f[x][1], f[i][0]);
    }
  f[x][0] += d;
  f[x][1]++;
}
void upd(pair<int, int> &x, pair<int, int> &y, pair<int, int> z) {
  if (z > x) swap(x, z);
  y = max(y, z);
}
void dfs2(int x, int fa) {
  if (!fa) g[x][0] = 0, g[x][1] = 0;
  pair<int, int> mx1(0, x), mx2(-1, -1), mx3(0, x), mx4(-1, -1);
  upd(mx1, mx2, pair<int, int>(max(g[x][0], g[x][1]) - 1, -1));
  upd(mx3, mx4, pair<int, int>(g[x][0], -1));
  for (auto i : e[x])
    if (i != fa) {
      upd(mx1, mx2, pair<int, int>(max(f[i][0], f[i][1]) - 1, i));
      upd(mx3, mx4, pair<int, int>(f[i][0], i));
    }
  int d = e[x].size() - 1;
  ans = max(ans, max(mx1.first + d + 1, mx3.first));
  for (auto i : e[x])
    if (i != fa) {
      g[i][0] = (mx1.second == i ? mx2.first : mx1.first) + d;
      g[i][1] = (mx3.second == i ? mx4.first : mx3.first) + 1;
      dfs2(i, x);
    }
}
int main() {
  srand(time(NULL));
  scanf("%d", &n);
  for (int i = (int)(1); i <= (int)(n - 1); i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    e[x].push_back(y);
    e[y].push_back(x);
  }
  dfs1(1, 0);
  dfs2(1, 0);
  printf("%d\n", ans);
}
