#include <bits/stdc++.h>
using namespace std;
std::mt19937 rnd(
    (int)std::chrono::steady_clock::now().time_since_epoch().count());
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 300000;
struct Res {
  int with, without, best;
};
int n;
vector<int> adj[MAXN];
Res dfs(int at, int par) {
  int nch = ((int)(adj[at]).size()) - (par != -1 ? 1 : 0);
  Res ret;
  ret.with = 1;
  ret.without = nch;
  ret.best = 0;
  int without1 = 0, without2 = 0;
  int any1 = 0, any2 = 0;
  for (int i = (0); i < (((int)(adj[at]).size())); ++i) {
    int to = adj[at][i];
    if (to == par) continue;
    Res sub = dfs(to, at);
    ret.with = max(ret.with, sub.without + 1);
    ret.without = max(ret.without, max(sub.with, sub.without) + nch - 1);
    ret.best = max(ret.best, sub.best);
    int anyc = max(sub.with, sub.without);
    if (anyc > any1)
      any2 = any1, any1 = anyc;
    else if (anyc > any2)
      any2 = anyc;
    int withoutc = sub.without;
    if (withoutc > without1)
      without2 = without1, without1 = withoutc;
    else if (withoutc > without2)
      without2 = withoutc;
  }
  ret.best = max(ret.best, max(ret.with, ret.without));
  if (nch >= 2)
    ret.best = max(ret.best, max(without1 + without2 + 1,
                                 any1 + any2 + ((int)(adj[at]).size()) - 2));
  return ret;
}
int solve() { return dfs(0, -1).best; }
void run() {
  scanf("%d", &n);
  for (int i = (0); i < (n - 1); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a, --b;
    adj[a].push_back(b), adj[b].push_back(a);
  }
  printf("%d\n", solve());
}
int main() {
  run();
  return 0;
}
