#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:60777216")
using namespace std;
int b;
vector<int> v[111111];
pair<int, int> dfs(int ver, int par = -1) {
  pair<int, int> res;
  vector<int> dont, other;
  for (int i = (0); i < (v[ver].size()); i++) {
    if (v[ver][i] == par) continue;
    pair<int, int> t = dfs(v[ver][i], ver);
    dont.push_back(t.second);
    other.push_back(max(t.first, t.second));
  }
  sort((dont).begin(), (dont).end());
  sort((other).begin(), (other).end());
  int tmp = 0;
  int t1 = 1;
  if (dont.size() > 0) t1 += dont.back();
  if (dont.size() > 1) t1 += dont[dont.size() - 2];
  int t2 = 0;
  if (other.size() > 0) t2 += other.back();
  if (other.size() > 1) t2 += other[other.size() - 2];
  if (other.size() > 2) t2 += other.size() - 2;
  if (par != -1) t2++;
  b = max(b, t1);
  b = max(b, t2);
  res.first = 1;
  if (dont.size() > 0) res.first += dont.back();
  res.second = 0;
  if (other.size() > 0) res.second += other.back();
  if (other.size() > 1) res.second += other.size() - 1;
  return res;
}
int main() {
  int n;
  cin >> n;
  for (int i = (0); i < (n - 1); i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--, y--;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  if (0 && n == 100000) {
    for (int i = (0); i < (n); i++)
      if (v[i].size() > 1) {
        b = 0;
        pair<int, int> t = dfs(i);
        if (b == 229)
          cout << max(b, max(t.first, t.second)) << ' ' << v[i].size() << endl;
      }
  }
  for (int i = (0); i < (n); i++)
    if (v[i].size() > 1) {
      b = 0;
      pair<int, int> t = dfs(i);
      break;
    }
  cout << b << endl;
  return 0;
}
