#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> adjlist[100005];
int dp[100005][2];
int ans = 0;
void dfs(int u, int p) {
  dp[u][0] = dp[u][1] = 0;
  int numchildren = adjlist[u].size() - (p != -1);
  if (numchildren == 0) {
    dp[u][0] = 1;
    dp[u][1] = 0;
    return;
  }
  int best1 = -1, best2 = -1;
  int A1 = 0, A2 = 0;
  int B1 = 0, B2 = 0;
  int C1 = 0, C2 = 0;
  for (auto v : adjlist[u]) {
    if (v == p) continue;
    dfs(v, u);
    int a = dp[v][1], b = max(dp[v][0], dp[v][1]);
    if (a >= A1) {
      A2 = A1;
      A1 = a;
    } else if (a >= A2)
      A2 = a;
    if (b >= B1) {
      B2 = B1;
      B1 = b;
    } else if (b >= B2)
      B2 = b;
  }
  dp[u][0] = 1 + A1;
  dp[u][1] = numchildren - 1 + B1;
  ans = max(ans, dp[u][0]);
  ans = max(ans, dp[u][1]);
  ans = max(ans, A1 + A2 + 1);
  ans = max(ans, numchildren - 2 + (p != -1) + B1 + B2);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    adjlist[a].push_back(b);
    adjlist[b].push_back(a);
  }
  dfs(1, -1);
  printf("%d", ans);
}
