#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> g[100005];
int dp[100005][2];
int ans = 0;
void dfs(int u, int du) {
  dp[u][0] = 0;
  dp[u][1] = 1;
  for (auto v : g[u]) {
    if (v == du) continue;
    dfs(v, u);
    ans = max(ans, dp[u][1] + dp[v][0]);
    ans = max(ans, dp[u][0] + max(dp[v][0], dp[v][1]));
    dp[u][1] = max(dp[u][1], dp[v][0] + 1);
    dp[u][0] = max(dp[u][0], max(dp[v][1], dp[v][0]) + int(g[u].size()) - 2);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, 0);
  cout << ans;
  return 0;
}
