#include <bits/stdc++.h>
using namespace std;
const int mxn = 100000;
int n;
int dp[mxn][2];
vector<int> g[mxn];
int dfs(int c, int p) {
  int ret = 0, d = g[c].size();
  for (int i : g[c])
    if (i != p) {
      ret = max(ret, dfs(i, c));
      ret = max({ret, dp[c][0] + dp[i][1] + 1, dp[c][1] + dp[i][0] + d - 2});
      for (int j = 0; j < 2; j++) dp[c][j] = max(dp[c][j], dp[i][!j]);
    }
  dp[c][0] = max(++dp[c][0], dp[c][1] += d - 1 - !!~p);
  ret = max(ret, dp[c][0]);
  return ret;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  cout << dfs(0, -1) << '\n';
  return 0;
}
