#include <bits/stdc++.h>
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
using namespace ::std;
const long long maxn = 1e5 + 500;
const long long inf = 1e9 + 800;
const long long mod = 1e9 + 7;
vector<long long> ger[maxn];
long long dpd[maxn];
long long par[maxn];
long long bach[maxn];
long long dpk[maxn];
void dfs(long long v, long long p = -1) {
  par[v] = p;
  long long mx = 0;
  long long mxx = 0;
  for (auto u : ger[v]) {
    if (u != p) {
      bach[v]++;
      dfs(u, v);
      mxx = max(mxx, dpd[u]);
      mx = max(mx, dpk[u]);
    }
  }
  dpd[v] = max(bach[v], mx + bach[v] - 1);
  dpk[v] = max(dpd[v], mxx + 1);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  for (long long i = 1; i < n; i++) {
    long long v, u;
    cin >> v >> u;
    v--;
    u--;
    ger[v].push_back(u);
    ger[u].push_back(v);
  }
  dfs(0);
  long long ans = 1;
  for (long long i = 0; i < n; i++) {
    ans = max(ans, dpd[i]);
    ans = max(ans, dpk[i]);
    if (bach[i] >= 2) {
      vector<long long> vec, veck;
      for (auto v : ger[i]) {
        if (v != par[i]) {
          vec.push_back(dpd[v]);
          veck.push_back(dpk[v]);
        }
      }
      sort(vec.begin(), vec.end());
      sort(veck.begin(), veck.end());
      ans = max(ans, vec[vec.size() - 1] + vec[vec.size() - 2] + 1);
      ans = max(ans, bach[i] - 2 + veck[veck.size() - 1] +
                         veck[veck.size() - 2] + (par[i] != -1));
    }
  }
  cout << ans;
}
