#include <bits/stdc++.h>
using namespace std;
int N, Ans;
vector<int> G[100005];
int f[100005], g[100005];
void DFS(int u, int p) {
  int cntch = 0;
  for (int v : G[u])
    if (v != p) ++cntch, DFS(v, u);
  if (!cntch) {
    f[u] = 1, g[u] = 0;
    return;
  }
  if (cntch == 1) {
    for (int v : G[u])
      if (v != p) f[u] = g[v] + 1, g[u] = max(f[v], g[v]);
    Ans = max(Ans, max(f[u], g[u] + (p != 0)));
    return;
  }
  int a1 = 0, a2 = 0;
  int b1 = 0, b2 = 0;
  f[u] = 1, g[u] = 0;
  for (int v : G[u])
    if (v != p) {
      a2 = max(a2, g[v]);
      if (a2 > a1) swap(a1, a2);
      b2 = max(b2, max(f[v], g[v]));
      if (b2 > b1) swap(b1, b2);
      f[u] = max(f[u], g[v] + 1);
      g[u] = max(g[u], max(f[v], g[v]) + cntch - 1);
    }
  int val = max(a1 + a2 + 1, b1 + b2 + cntch - 2 + (p != 0));
  Ans = max(Ans, val);
}
int main() {
  scanf("%d", &N), Ans = 1;
  for (int i = 1, x, y; i < N; ++i) {
    scanf("%d%d", &x, &y);
    G[x].push_back(y), G[y].push_back(x);
  }
  DFS(1, 0);
  printf("%d\n", Ans);
  return 0;
}
