#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int to, nex;
  Edge(int _ = 0, int __ = 0) { to = _, nex = __; }
} e[100005 << 1];
int n, ans, cnt, hd[100005], dep[100005], du[100005], dp[100005][2];
int rd() {
  int x = 0, tp = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') tp = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x * 10 + c - '0');
    c = getchar();
  }
  return x * tp;
}
void adde(int x, int y) {
  e[++cnt] = Edge(y, hd[x]);
  hd[x] = cnt;
}
void dfs(int now, int fa) {
  dep[now] = dep[fa] + 1, dp[now][1] = 1;
  for (int i = hd[now]; i; i = e[i].nex) {
    if (e[i].to != fa) {
      dfs(e[i].to, now);
      ans = max(ans, max(dp[now][0] + max(dp[e[i].to][0], dp[e[i].to][1]),
                         dp[now][1] + dp[e[i].to][0]));
      dp[now][0] =
          max(dp[now][0], max(dp[e[i].to][0], dp[e[i].to][1]) + du[now] - 2);
      dp[now][1] = max(dp[now][1], dp[e[i].to][0] + 1);
    }
  }
  ans = max(ans, dp[now][1]);
}
int main() {
  int x, y;
  n = rd();
  for (int i = 1; i < n; i++) {
    x = rd(), y = rd();
    adde(x, y), adde(y, x);
    du[x]++, du[y]++;
  }
  dfs(1, 0);
  printf("%d\n", ans);
  return 0;
}
