#include <bits/stdc++.h>
using namespace std;
struct P {
  vector<long long int> p = {0, 0};
  void add(long long int x) {
    p.push_back(x);
    sort((p).begin(), (p).end(), greater<long long int>());
    while (((long long int)(p).size()) > 2) p.pop_back();
  }
  long long int operator[](long long int x) { return p[x]; }
};
vector<long long int> adj[100005];
vector<vector<long long int>> dp(100005, vector<long long int>(2, 0));
long long int ans = 0;
void dfs(long long int x, long long int p) {
  P a, b;
  for (auto y : adj[x]) {
    if (y == p) continue;
    dfs(y, x);
    a.add(max(dp[y][0], dp[y][1]));
    b.add(dp[y][0]);
  }
  long long int c = a[0] + a[1];
  c += ((long long int)(adj[x]).size()) - (a[0] > 0) - (a[1] > 0);
  ans = max(ans, c);
  c = b[0] + b[1] + 1;
  ans = max(ans, c);
  dp[x][0] = a[0] + ((long long int)(adj[x]).size()) - (a[0] > 0) - (p > 0);
  dp[x][1] = b[0] + 1;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  for (long long int i = 0; i < n - 1; i++) {
    long long int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(1, 0);
  cout << ans;
}
