#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100111;
vector<int> edg[MAXN];
int par[MAXN];
int dpt[MAXN];
int dpn[MAXN];
int ans = 1;
void dfs(int v) {
  dpn[v] = edg[v].size() - 1;
  if (v == 1) dpn[v]++;
  dpt[v] = 1;
  int max_score_n = 0;
  int max_score_t = 0;
  for (auto b : edg[v]) {
    if (par[v] == b) continue;
    par[b] = v;
    dfs(b);
    ans = max(ans, dpn[b] + max_score_n + max(1, (int)edg[v].size() - 2));
    ans = max(ans, max(dpn[b], dpt[b]) + max(max_score_n, max_score_t) +
                       (int)edg[v].size() - 2);
    max_score_n = max(max_score_n, dpn[b]);
    max_score_t = max(max_score_t, dpt[b]);
    dpt[v] = max(dpt[v], 1 + dpn[b]);
    dpn[v] = max(dpn[v], (int)edg[v].size() - 2 + max(dpt[b], dpn[b]));
  }
  ans = max(ans, max(dpt[v], dpn[v]));
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = (2); i <= (n); i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    edg[a].push_back(b);
    edg[b].push_back(a);
  }
  dfs(1);
  printf("%d\n", ans);
}
