#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, ans;
vector<int> g[N];
int f[N][2];
void dfs(int u, int fa) {
  f[u][0] = f[u][1] = 0;
  for (auto v : g[u]) {
    if (v ^ fa) {
      dfs(v, u);
      ans = max(ans, f[u][1] + f[v][0] + 1);
      ans = max(ans, f[u][0] + (int)g[u].size() - 2 + max(f[v][0], f[v][1]));
      f[u][0] = max(f[u][0], max(f[v][1], f[v][0]));
      f[u][1] = max(f[u][1], f[v][0]);
    }
  }
  f[u][1]++;
  if (g[u].size() >= 2) f[u][0] += g[u].size() - 2;
  ans = max(ans, max(f[u][0], f[u][1]));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  ans = 0;
  dfs(1, 0);
  printf("%d\n", ans);
  return 0;
}
