#include <bits/stdc++.h>
using namespace std;
const int nax = 1e5 + 100;
vector<int> g[nax];
int ans;
int dp[nax][2];
void dfs(int u, int p) {
  int child = g[u].size() - !!p;
  pair<int, int> mx0 = {0, 0}, mx1{0, 0};
  for (int v : g[u]) {
    if (v == p) continue;
    dfs(v, u);
    int v0 = max(dp[v][1], dp[v][0]), v1 = dp[v][0];
    if (v0 > mx0.first) swap(v0, mx0.first);
    if (v0 > mx0.second) swap(v0, mx0.second);
    if (v1 > mx1.first) swap(v1, mx1.first);
    if (v1 > mx1.second) swap(v1, mx1.second);
  }
  ans = max(ans, mx1.first + mx1.second + 1);
  ans = max(ans, mx0.first + mx0.second + max(0, (int)g[u].size() - 2));
  dp[u][0] = mx0.first + max(0, child - 1);
  dp[u][1] = mx1.first + 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, 0);
  cout << ans << '\n';
}
