#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
const long long int inf = 2.19e15 + 1;
const long double pai = 3.141592653589793238462643383279502884197;
const long double eps = 1e-10;
template <class T, class U>
bool chmin(T& a, U b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T, class U>
bool chmax(T& a, U b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
long long int gcd(long long int a, long long int b) {
  if (a % b == 0) {
    return b;
  } else
    return gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
  if (a == 0) {
    return b;
  }
  return a / gcd(a, b) * b;
}
template <class T>
void SO(T& ve) {
  sort(ve.begin(), ve.end());
}
template <class T>
void REV(T& ve) {
  reverse(ve.begin(), ve.end());
}
template <class T>
long long int LBI(const vector<T>& ar, T in) {
  return lower_bound(ar.begin(), ar.end(), in) - ar.begin();
}
template <class T>
long long int UBI(const vector<T>& ar, T in) {
  return upper_bound(ar.begin(), ar.end(), in) - ar.begin();
}
vector<vector<int>> go;
tuple<int, int, int> dfs(int ter, int per) {
  int ansA = 0, ansB = 0, ansC = 0;
  int zi = go[ter].size();
  for (auto it : go[ter]) {
    if (it == per) {
      continue;
    }
    auto ret = dfs(it, ter);
    int a, b, c;
    tie(a, b, c) = ret;
    chmax(ansA, a);
    chmax(ansA, ansB + c + zi - 2);
    chmax(ansA, ansC + b + 1);
    chmax(ansC, b);
    chmax(ansB, c);
  }
  ansB += zi - 2;
  ansC++;
  chmax(ansC, ansB);
  return make_tuple(ansA, ansB, ansC);
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int i, n;
  cin >> n;
  go.resize(n);
  for (i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    go[a].push_back(b);
    go[b].push_back(a);
  }
  auto ret = dfs(0, -1);
  cout << get<0>(ret) << endl;
}
