#include <bits/stdc++.h>
using namespace std;
inline int read() {
  register char c = ' ';
  register int v = 0, x = 1;
  while ((c < '0') || (c > '9')) {
    if (c == '-') x = -1;
    c = getchar();
  }
  while ((c >= '0') && (c <= '9')) {
    v = (v << 1) + (v << 3) + (c ^ 48);
    c = getchar();
  }
  return v * x;
}
inline void write(register int x) {
  if (x < 0) x = -x, putchar('-');
  if (x > 9) write(x / 10);
  putchar(x % 10 ^ 48);
}
const int N = 2e5 + 10;
int ans, fa[N], dep[N], dp[N][3];
int n, cnt, head[N], v[N], nxt[N], ind[N];
inline void add(register int x, register int y) {
  ind[x]++, ind[y]++;
  v[++cnt] = y, nxt[cnt] = head[x], head[x] = cnt;
  v[++cnt] = x, nxt[cnt] = head[y], head[y] = cnt;
}
inline void dfs(register int u) {
  dep[u] = dep[fa[u]] + 1;
  dp[u][0] = 0, dp[u][1] = 1;
  for (register int i = head[u]; i; i = nxt[i])
    if (v[i] != fa[u]) {
      fa[v[i]] = u;
      dfs(v[i]);
      ans = max(ans, dp[u][0] + dp[v[i]][0]);
      ans = max(ans, dp[u][1] + dp[v[i]][0]);
      ans = max(ans, dp[u][0] + dp[v[i]][1]);
      dp[u][0] = max(dp[u][0], dp[v[i]][0] + ind[u] - 2);
      dp[u][0] = max(dp[u][0], dp[v[i]][1] + ind[u] - 2);
      dp[u][1] = max(dp[u][1], dp[v[i]][0] + 1);
    }
  ans = max(ans, dp[u][1]);
}
int main() {
  n = read();
  for (register int i = 1; i < n; i++) add(read(), read());
  dfs(1);
  write(ans);
  return ~~(0 - 0);
}
