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

const int mx = 1e5+5;
int n;
set<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;

}

void debug(int d, basic_string<int> a, basic_string<int> b) {

    cout << d << '\n';
    for (auto x : a)
        cout << x << ' ';
    cout << '\n';
    for (auto x : b)
        cout << x << ' ';
    cout << '\n';

}

int solve(int wh, int bl) {

    if (n <= 4) return 2;

    int arb = 1; while (e[arb].empty()) arb++;
    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(!a.empty() && !b.empty());
    assert(dx == dy);
    int d = dx;
    if (b.size() < a.size())
        swap(a, b);

    //debug(d, a, b);

    if (a.size() > 1) 
        return d;

    if (wh > bl && b.size()%2==0)
        return d;
    
    if (wh > bl+1)
        return d;
    
    int k = a[0];
    for (auto i : e[k]) {
        e[i].erase(k);
    }
    e[k].clear();
    return solve(wh, bl-1);

}

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].insert(y);
        e[y].insert(x);
    }

    cout << solve((n+1)/2, n/2) << '\n';

}