#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using pii = pair<int, int>;
using vi = vector<int>;
const int N = 1e5 + 100;
int n, d[N], f[N][2], ans;
vi G[N];
void dfs(int x, int fz) {
  f[x][0] = 0, f[x][1] = 1;
  for (int y : G[x])
    if (y != fz) {
      dfs(y, x);
      ans = max({ans, f[x][0] + f[y][0], f[x][0] + f[y][1], f[x][1] + f[y][0]});
      f[x][0] = max({f[x][0], f[y][0] + d[x] - 2, f[y][1] + d[x] - 2});
      f[x][1] = max({f[x][1], f[y][0] + 1});
    }
  ans = max(ans, f[x][1]);
}
signed main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    G[x].push_back(y), G[y].push_back(x);
    d[x]++, d[y]++;
  }
  dfs(1, 0);
  printf("%d\n", ans);
  fprintf(stderr, "time=%.4f\n", (db)clock() / CLOCKS_PER_SEC);
  return 0;
}
