#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v[n + 1];
  for (int i = 1; i <= n - 1; i++) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  int res = 0;
  vector<array<int, 2>> dp(n + 1, {0, 0});
  vector<int> d(n + 1, 0);
  function<void(int, int)> dfs = [&](int a, int p) {
    d[a] = v[a].size();
    res = max(res, d[a]);
    dp[a] = {d[a] - 1, 1};
    vector<int> zero, one;
    for (int to : v[a]) {
      if (to == p) continue;
      dfs(to, a);
      zero.push_back(max(dp[to][0], dp[to][1]));
      one.push_back(dp[to][0]);
      dp[a][0] = max(dp[a][0], max(dp[to][0], dp[to][1]) + d[a] - 2);
      dp[a][1] = max(dp[a][1], dp[to][0] + 1);
      res = max(res, max(dp[to][0], dp[to][1]) + d[a] - 1);
      res = max(res, dp[to][0] + 1);
    }
    sort(zero.begin(), zero.end(), greater<int>());
    sort(one.begin(), one.end(), greater<int>());
    if (zero.size() >= 2) {
      res = max(res, zero[0] + zero[1] + d[a] - 2);
      res = max(res, one[0] + one[1] + 1);
    }
  };
  dfs(1, 0);
  cout << res << "\n";
  return 0;
}
