#include <bits/stdc++.h>
template <class Tp>
void read(Tp &res) {
  static char ch;
  ch = getchar(), res = 0;
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) res = res * 10 + ch - 48, ch = getchar();
}
const int MAXN = 1e5 + 19;
struct Edge {
  int to, next;
} edge[MAXN * 2];
int head[MAXN], cnt;
inline void add(int from, int to) {
  edge[++cnt].to = to;
  edge[cnt].next = head[from];
  head[from] = cnt;
}
int n, deg[MAXN], dp[MAXN][2], ans;
inline void ins(int v, int &a, int &b) {
  if (v > a)
    b = a, a = v;
  else if (v > b)
    b = v;
}
inline int chkpos(int a) { return a > 0 ? a : 0; }
void dfs(int node, int f) {
  int m0 = 0, m1 = 0, k0 = 0, k1 = 0;
  for (int i = head[node]; i; i = edge[i].next)
    if (edge[i].to != f) {
      dfs(edge[i].to, node);
      ins(std::max(dp[edge[i].to][0], dp[edge[i].to][1]), m0, m1);
      ins(dp[edge[i].to][0], k0, k1);
    }
  ans = std::max(ans, m0 + m1 + deg[node] - 2);
  ans = std::max(ans, k0 + k1 + 1);
  ans = std::max(ans, m0 + deg[node] - 1);
  ans = std::max(ans, k0 + 1);
  dp[node][0] = m0 + chkpos(deg[node] - 2);
  dp[node][1] = k0 + 1;
}
int main() {
  read(n);
  for (int i = 2; i <= n; ++i) {
    int a, b;
    read(a), read(b);
    add(a, b), add(b, a), ++deg[b], ++deg[a];
  }
  dfs(1, 0);
  printf("%d\n", ans);
  return 0;
}
