#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int n;
vector<int> g[N];
int ans = 0;
int dp[N][2];
void dfs(int v, int last = -1) {
  dp[v][1] = 1;
  for (int u : g[v]) {
    if (u != last) {
      dfs(u, v);
      ans = max(ans,
                max(dp[v][0] + dp[u][1], max(dp[v][1], dp[v][0]) + dp[u][0]));
      dp[v][1] = max(dp[v][1], dp[u][0] + 1);
      dp[v][0] = max(dp[v][0], max(dp[u][0], dp[u][1]) + (int)g[v].size() - 2);
    }
  }
  ans = max(ans, dp[v][1]);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int v, u;
    cin >> v >> u;
    --v, --u;
    g[v].push_back(u);
    g[u].push_back(v);
  }
  dfs(0);
  cout << ans << '\n';
  return 0;
}
