#include <bits/stdc++.h>
using namespace std;
const long long N = (long long)(1e6) + 322;
const long long MAXN = (long long)(1e7) + 100;
const long long inf = (long long)(3e18) + 322;
const long long mod = 998244353;
const double eps = 1e-6;
long long dp[N][3];
vector<long long> v[N];
long long ans = 0;
long long n;
void dfs(long long x, long long p = -1) {
  long long deg = (long long)(v[x].size()) - (p != -1);
  dp[x][0] = 1;
  dp[x][1] = deg;
  for (auto to : v[x]) {
    if (to == p) continue;
    dfs(to, x);
    dp[x][0] = max(dp[x][0], dp[to][1] + 1);
    dp[x][1] = max(dp[x][1], max(dp[to][0], dp[to][1]) + deg - 1);
  }
  long long mx0 = 0;
  long long mx1 = 0;
  for (long long to : v[x]) {
    if (to == p) continue;
    ans = max(ans, dp[to][1] + mx1 + 1);
    ans = max(ans, max(dp[to][1], dp[to][0]) + max(mx1, mx0) +
                       ((long long)(v[x].size()) - 2));
    mx1 = max(mx1, dp[to][1]);
    mx0 = max(mx0, dp[to][0]);
  }
}
void solve() {
  cin >> n;
  for (long long i = 1; i < n; ++i) {
    long long x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(1);
  cout << ans;
}
signed main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
