#include <bits/stdc++.h>
using namespace std;
int const N = 100000;
int dp1[N + 1], dp2[N + 1], n, an;
vector<int> tr[N + 1];
int V;
void go(int v = 1, int p = 0) {
  int ch = 0, m = 0;
  for (int u : tr[v])
    if (u != p) {
      ++ch;
      go(u, v);
      dp2[v] = max(dp2[v], dp1[u]);
      m = max(m, dp2[u]);
    }
  int m1 = 0, m2 = 0;
  for (int u : tr[v]) {
    int t = max(dp2[u], -1 + dp1[u]);
    if (t > m1)
      m2 = m1, m1 = t;
    else if (t > m2)
      m2 = t;
  }
  an = max(an, (int)tr[v].size() + m1 + m2);
  m1 = m2 = 0;
  for (int u : tr[v]) {
    int t = dp1[u];
    if (t > m1)
      m2 = m1, m1 = t;
    else if (t > m2)
      m2 = t;
  }
  an = max(an, m1 + m2 + 1);
  dp1[v] = ch + max(m, -1 + dp2[v]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < (int)(n); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    tr[a].push_back(b);
    tr[b].push_back(a);
  }
  go();
  printf("%d\n", an);
}
