#include <bits/stdc++.h>
using namespace std;
int nxt[(100010) * 2], v[(100010) * 2], hd[(100010)], d[(100010)];
void adde(int a, int b, int id) {
  v[id] = b;
  nxt[id] = hd[a];
  hd[a] = id;
  ++d[a];
}
int f[(100010) * 2], g[2 * (100010)], sf[(100010)][2], sg[(100010)][2];
void update(int x[2], int y) {
  if (y > x[0]) {
    x[1] = x[0];
    x[0] = y;
  } else if (y > x[1]) {
    x[1] = y;
  }
}
void up(int x, int fa) {
  for (int i = hd[x]; i; i = nxt[i]) {
    int y = v[i];
    if (y != fa) {
      up(y, x);
      f[i ^ 1] = d[y] == 1 ? 0 : max(sg[y][0], sf[y][0]) + d[y] - 2;
      g[i ^ 1] = d[y] == 1 ? 1 : sf[y][0] + 1;
      update(sf[x], f[i ^ 1]);
      update(sg[x], g[i ^ 1]);
    }
  }
}
void down(int x, int id) {
  update(sf[x], f[id]);
  update(sg[x], g[id]);
  for (int i = hd[x]; i; i = nxt[i]) {
    int y = v[i];
    if ((i ^ 1) != id) {
      int mf = sf[x][f[i ^ 1] == sf[x][0]], mg = sg[x][g[i ^ 1] == sg[x][0]];
      f[i] = max(mf, mg) + d[x] - 2;
      g[i] = mf + 1;
      down(y, i);
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1, a, b; i < n; ++i) {
    scanf("%d%d", &a, &b);
    adde(a, b, i << 1);
    adde(b, a, i << 1 | 1);
  }
  int root;
  for (root = 1; root <= n && d[root] == 1; ++root)
    ;
  up(root, 0);
  down(root, 0);
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    int mf = 0, mg = 0;
    for (int j = hd[i]; j; j = nxt[j]) {
      mf = max(mf, f[j ^ 1]);
      mg = max(mg, g[j ^ 1]);
    }
    ans = max(ans, mg + d[i] - 1);
    ans = max(ans, mf + 1);
  }
  printf("%d\n", ans);
}
