#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ii = pair<ll, ll>;
ll n, a, b, d[100050][2], vst[100050], ret;
vector<ll> adj[100050];
void dfs(ll src) {
  vst[src] = 1;
  ll cnt = 0, mx0 = -9999, nmx0 = -9999, mx1 = -9999, nmx1 = -9999, mp0 = -1,
     mp1 = -1;
  for (int i = (0); i < (adj[src].size()); i++) {
    ll there = adj[src][i];
    if (!vst[there]) {
      dfs(there);
      cnt++;
      if (d[there][0] > mx0) {
        nmx0 = mx0;
        mx0 = d[there][0];
        mp0 = there;
      } else {
        if (d[there][0] > nmx0) {
          nmx0 = d[there][0];
        }
      }
      if (d[there][1] > mx1) {
        nmx1 = mx1;
        mx1 = d[there][1];
        mp1 = there;
      } else {
        if (d[there][1] > nmx1) {
          nmx1 = d[there][1];
        }
      }
    }
  }
  if (cnt) {
    d[src][0] = mx1;
    d[src][1] = max(mx0 + cnt, mx1 + cnt - 1);
    if (cnt >= 2) {
      ret = max(
          {ret, mx1 + nmx1 + 1, nmx0 + mx0 + cnt + 1, mx1 + nmx1 + cnt - 1});
      if (mp0 != mp1) {
        ret = max(ret, mx1 + mx0 + cnt);
      } else {
        ret = max({ret, mx1 + nmx0 + cnt, nmx1 + mx0 + cnt});
      }
    }
  }
}
int main() {
  cin.tie(nullptr);
  cout.tie(nullptr);
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = (0); i < (n - 1); i++) {
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  for (int i = (1); i < (n + 1); i++) {
    if (adj[i].size() == 1) {
      dfs(i);
      ret = max({ret, d[i][0] + 1, d[i][1]});
      break;
    }
  }
  cout << ret << endl;
  return 0;
}
