#include <bits/stdc++.h>
inline int getint() {
  int x = 0, p = 1;
  char c = getchar();
  while (c <= 32) c = getchar();
  if (c == 45) p = -p, c = getchar();
  while (c > 32) x = x * 10 + c - 48, c = getchar();
  return x * p;
}
using namespace std;
const int mod = 1e9 + 7;
inline void reduce(int &x) { x += x >> 31 & mod; }
inline int mul(int x, int y) { return 1ll * x * y % mod; }
const int N = 1e5 + 5;
int n, f[N][2], res = 1;
vector<int> g[N];
void dfs(int x, int p) {
  int c = 0;
  f[x][1] = 1;
  for (int to : g[x])
    if (to != p) {
      dfs(to, x);
      ++c;
    }
  int pre[2] = {0, 0};
  for (int to : g[x])
    if (to != p) {
      f[x][1] = max(f[x][1], f[to][0] + 1);
      f[x][0] = max(f[x][0], max(f[to][1], f[to][0]) + c - 1);
      res = max(res, f[to][1] + pre[0]);
      res = max(res, f[to][0] + pre[1]);
      pre[0] = max(pre[0], max(f[to][1], f[to][0]) + c + (p >= 0) - 2);
      pre[1] = max(pre[1], max(pre[0], f[to][0] + 1));
    }
  res = max(res, max(f[x][0], f[x][1]));
}
int main() {
  n = getint();
  for (int(i) = 0; (i) < (n - 1); (i)++) {
    int x = getint() - 1, y = getint() - 1;
    g[x].emplace_back(y);
    g[y].emplace_back(x);
  }
  dfs(0, -1);
  printf("%d\n", res);
  return 0;
}
