#include <bits/stdc++.h>
int read() {
  static int c, x;
  while ((c = getchar()) < 48) {
  }
  x = c & 15;
  while ((c = getchar()) >= 48) x = x * 10 + (c & 15);
  return x;
}
struct edge {
  int next, to;
} e[100010 << 1];
int ans = 0;
int head[100010], deg[100010], f0[100010], f1[100010];
inline void add(const int &x, const int &y) {
  static int ei;
  e[++ei].next = head[x];
  e[ei].to = y;
  head[x] = ei;
  ++deg[x];
}
void dfs(const int &x, const int &fa) {
  f1[x] = 1;
  f0[x] = deg[x] - 1;
  for (int i = head[x]; i; i = e[i].next) {
    const int y = e[i].to;
    if (y != fa) {
      dfs(y, x);
      ans = std::max(ans, f0[x] + std::max(f0[y], f1[y]));
      ans = std::max(ans, f1[x] + f0[y]);
      f0[x] = std::max(f0[x], std::max(f0[y], f1[y]) + deg[x] - 2);
      f1[x] = std::max(f1[x], f0[y] + 1);
    }
  }
}
int main() {
  const int n = read();
  for (int i = n; --i;) {
    const int x = read(), y = read();
    add(x, y);
    add(y, x);
  }
  dfs(1, 0);
  printf("%d\n", ans);
  return 0;
}
