#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int f[N][2], n;
vector<int> g[N];
int dfs(int u, int fa) {
  int _ans = 0, child = 0;
  for (auto v : g[u])
    if (v != fa) _ans = max(_ans, dfs(v, u)), ++child;
  int pre0 = 0, pre1 = 0;
  f[u][0] = child;
  f[u][1] = max(1, child);
  for (auto v : g[u])
    if (v != fa) {
      _ans = max(_ans, max(pre0 + f[v][0] + 1,
                           pre1 + f[v][1] + child - 2 + (fa != -1)));
      pre0 = max(pre0, f[v][0]);
      pre1 = max(pre1, f[v][1]);
      f[u][0] = max(f[u][0], f[v][1] + child - 1);
      f[u][1] = max(f[u][1], max(f[v][0] + 1, f[v][1] + child - 1));
    }
  _ans = max(_ans, f[u][0]);
  return _ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 1, u, v; i < n; ++i) {
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int ans = dfs(1, -1);
  printf("%d\n", ans);
  return 0;
}
