#include <bits/stdc++.h>
using namespace std;
const int MX_N = 1e5 + 5;
int N;
vector<int> al[MX_N];
int f[MX_N][2], g[MX_N];
void dfs(int u, int p = 0) {
  f[u][0] = 0;
  f[u][1] = 1;
  for (int v : al[u])
    if (v != p) {
      dfs(v, u);
      g[u] =
          max(g[u], f[u][0] + max(f[v][0], f[v][1]) + (int)(al[u]).size() - 2);
      g[u] = max(g[u], f[u][1] + f[v][0]);
      f[u][0] = max(f[u][0], max(f[v][0], f[v][1]));
      f[u][1] = max(f[v][0], f[v][0] + 1);
    }
  f[u][0] = max(0, f[u][0] + (int)(al[u]).size() - (p > 0) - 1);
  g[u] = max(g[u], max(f[u][0] + (p > 0), f[u][1]));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  for (int i = (1); i <= (N - 1); ++i) {
    int A, B;
    cin >> A >> B;
    al[A].push_back(B);
    al[B].push_back(A);
  }
  dfs(1);
  int ans = 0;
  for (int i = (1); i <= (N); ++i) {
    ans = max(ans, g[i]);
  }
  cout << ans;
}
