#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001;
vector<int> graph[MX];
int dp[MX][2];
int ans = 1;
void dfs(int v, int p) {
  int dif = 0, dif2 = 0;
  int sum = 1;
  int cnt = 0;
  for (int i = 0; i < ((int)(graph[v]).size()); i++) {
    int nxt = graph[v][i];
    if (nxt == p) continue;
    dfs(nxt, v);
    cnt++;
    dif = max(dif, max(dp[nxt][0], dp[nxt][1]) - 1);
    dif2 = max(dif2, dp[nxt][0]);
  }
  dp[v][0] = cnt + dif;
  dp[v][1] = 1 + dif2;
}
void dfs2(int v, int p, int A, int B) {
  vector<int> difs;
  difs.push_back(0);
  difs.push_back(0);
  difs.push_back(0);
  difs.push_back(0);
  vector<int> difs2;
  difs2.push_back(0);
  difs2.push_back(0);
  difs2.push_back(0);
  difs2.push_back(0);
  int sum = 1;
  int cnt = 0;
  for (int i = 0; i < ((int)(graph[v]).size()); i++) {
    int nxt = graph[v][i];
    if (nxt == p) continue;
    cnt++;
    difs.push_back(max(dp[nxt][0], dp[nxt][1]) - 1);
    difs2.push_back(dp[nxt][0]);
    sum += dp[nxt][0];
  }
  if (p != -1) {
    cnt++;
    sum += A;
    difs.push_back(max(A, B) - 1);
    difs2.push_back(A);
  }
  sort(difs.begin(), difs.end());
  reverse(difs.begin(), difs.end());
  sort(difs2.begin(), difs2.end());
  reverse(difs2.begin(), difs2.end());
  ans = max(ans, max(cnt, 0) + difs[0] + difs[1]);
  ans = max(ans, difs2[0] + difs2[1] + 1);
  for (int i = 0; i < ((int)(graph[v]).size()); i++) {
    int nxt = graph[v][i];
    if (nxt == p) continue;
    int nA = max(cnt - 1, 0);
    if (max(dp[nxt][0], dp[nxt][1]) - 1 == difs[0]) {
      nA += difs[1];
    } else {
      nA += difs[0];
    }
    int nB = difs2[0];
    if (difs2[0] == dp[nxt][0]) nB = difs2[1];
    nB++;
    dfs2(nxt, v, nA, nB);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int N;
  cin >> N;
  for (int i = 0; i < (N - 1); i++) {
    int A, B;
    cin >> A >> B;
    A--;
    B--;
    graph[A].push_back(B);
    graph[B].push_back(A);
  }
  dfs(0, -1);
  dfs2(0, -1, 0, 0);
  cout << ans << nl;
  return 0;
}
