#include <bits/stdc++.h>
using namespace std;

const int mx = 1e5+5;
int n;
vector<int> e[mx];

int farthest(int x, int d = 0, int p = 0) {

    int ans = d;

    for (auto i : e[x]) {
        if (i == p)
            continue;
        
        ans = max(ans, farthest(i, d+1, x));
    }

    return ans;

}

basic_string<int> findOnDist(int x, int k, int d = 0, int p = 0) {

    if (d == k)
        return {x};

    basic_string<int> ans;

    for (auto i : e[x]) {
        if (i == p)
            continue;
        ans += findOnDist(i, k, d+1, x);
    }

    return ans;

}

signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    cin >> n;
    for (int i = 1; i < n; i++) {
        int x, y;
        cin >> x >> y;
        e[x].push_back(y);
        e[y].push_back(x);
    }

    int arb = 1;
    int darb = farthest(arb);
    basic_string<int> arbarr = findOnDist(arb, darb);

    int x = arbarr[0];
    int dx = farthest(x);
    basic_string<int> a = findOnDist(x, dx);

    int y = a[0];
    int dy = farthest(y);
    basic_string<int> b = findOnDist(y, dy);

    assert(dx == dy);
    int d = dx;

    assert(!a.empty() && !b.empty());

    if (a.size() >= 2 && b.size() >= 2) {
        cout << d << '\n';
        return 0;
    }

    if (b.size() == 1)
        swap(a, b);

    if (n%2==1 && b.size()%2==0) {
        cout << d << '\n';
        return 0;
    }
    
    cout << d-1 << '\n';
    return 0;

}