#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> g, dp;
int ans = 0;
void dfs(int v, int p = -1) {
  int deg = g[v].size();
  int max1 = 0, max0 = 0;
  dp[v][0] = 1;
  for (auto u : g[v]) {
    if (u != p) {
      dfs(u, v);
      ans = max(ans, dp[u][0] + max0 + 1);
      ans = max(ans, dp[u][0] + max0 + deg - 2);
      ans = max(ans, dp[u][0] + max1 + deg - 2);
      ans = max(ans, dp[u][1] + max1 + deg - 2);
      ans = max(ans, max0 + dp[u][1] + deg - 2);
      max1 = max(max1, dp[u][1]);
      max0 = max(max0, dp[u][0]);
    }
  }
  int ch = deg - (p != -1);
  dp[v][0] = max(0, ch - 1 + max(max0, max1));
  dp[v][1] = max0 + 1;
}
int main() {
  int n;
  cin >> n;
  g.resize(n);
  dp = vector<vector<int>>(n, vector<int>(2));
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (auto e : dp) {
    for (auto z : e) ans = max(ans, z);
  }
  dfs(0);
  cout << ans;
}
