#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
const int oo = 2e9;
const long long OO = 1e18;
const int md = 998244353;
const int PW = 40;
vector<int> g[N];
int f[2][N], n;
int ans = 0;
void dfs(int v, int p) {
  f[0][v] = 1;
  int kol = 0, b0 = -1, b1 = -1, n0 = -1, n1 = -1;
  for (int u : g[v]) {
    if (u == p) continue;
    dfs(u, v);
    kol++;
    if (b0 < f[1][u]) {
      b0 = f[1][u];
      n0 = u;
    }
    if (b1 < max(f[1][u], f[0][u])) {
      b1 = max(f[1][u], f[0][u]);
      n1 = u;
    }
  }
  if (b0 != -1) f[0][v] += b0;
  if (b1 != -1) f[1][v] += b1 + kol - 1;
  for (int u : g[v]) {
    if (u == p) continue;
    if (n0 != u) ans = max(ans, f[0][v] + f[1][u]);
    if (n1 != u)
      ans = max(ans, f[1][v] + max(f[1][u], f[0][u]) + bool(p != -1) - 1);
  }
  ans = max(ans, max(f[0][v], f[1][v] + bool(p != -1)));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  int rt = n - 1;
  dfs(0, -1);
  cout << ans;
  return 0;
}
