#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops, no-stack-protector")
#pragma GCC target("avx,avx2,fma")
using namespace std;
const long long maxn = 2e5 + 30;
const long long mod = 1e9 + 7;
const long long base = 1e9;
vector<long long> adj[maxn];
long long dp[maxn][2];
long long ans = 0;
void dfs(long long u, long long par) {
  dp[u][1] = 1;
  dp[u][0] = adj[u].size() - (par != 0);
  long long t = adj[u].size() - (par != 0);
  for (auto to : adj[u]) {
    if (to == par) continue;
    dfs(to, u);
    ans = max(ans, dp[u][1] + dp[to][0]);
    ans = max(ans, dp[u][0] - 1 + (par != 0) + max(dp[to][0], dp[to][1]));
    dp[u][1] = max(dp[u][1], dp[to][0] + 1);
    dp[u][0] = max(dp[u][0], max(dp[to][0], dp[to][1]) + t - 1);
  }
  ans = max(ans, max(dp[u][1], dp[u][0]));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  if (fopen("t.inp", "r")) {
    freopen("test.inp", "r", stdin);
    freopen("test.out", "w", stdout);
  }
  long long n;
  cin >> n;
  for (int i = 1; i <= n - 1; i++) {
    long long x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(1, 0);
  cout << ans << "\n";
}
