#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<vector<int>> g(n + 1);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<array<int, 2>> dp(n + 1);
  int res = 0;
  function<void(int, int)> dfs = [&](int v, int p) {
    int cnt = g[v].size();
    dp[v][0] = 1;
    dp[v][1] = cnt;
    for (auto w : g[v]) {
      if (w == p) continue;
      dfs(w, v);
      res = max(res, dp[v][1] - 1 + max(dp[w][0], dp[w][1] - 1));
      res = max(res, dp[v][0] + dp[w][1] - 1);
      dp[v][0] = max(dp[v][0], dp[w][1]);
      dp[v][1] = max(dp[v][1], cnt - 1 + max(dp[w][0], dp[w][1] - 1));
    }
  };
  dfs(1, 0);
  res = max(res, max(dp[1][0], dp[1][1]));
  cout << res << endl;
  return 0;
}
