#include <bits/stdc++.h>

using namespace std;
int n,a,b;
vector< vector<int> > tree;
queue <int> leaf;
queue <int> deep;
vector <int> been;
vector <bool> visited;
vector <int> candidates;
//map <int,multiset<int,greater<int>>> mapa;

int lar1,lar2;

int dfs2(int from,int to,int dept)
{
    //cout<<" -"<<to+1<<endl;
    been[to] = dept;
    //mapa[indec].insert(dept);
    int l=0;
    for(auto it : tree[to]) if(it != from)
    {
    b=dfs2(to,it,dept+1);
    //cout<<">"<<to+1<<" "<<it+1<<" "<<b<<endl;
        l = max(l,b);
    }
    //cout<<"iz "<<to+1<<" "<<l+1<<endl;
    return l+1;
}
void dfs(int from)
{
    lar1=0;lar2=0;
    been[from] = 0;
    for(auto it : tree[from]) //cout<<""<<dfs2(from,it,1)<<endl;
    {
        //mapa.clear();
        b=dfs2(from,it,1);
        lar2=max(lar2,b);
        if(lar1<lar2)swap(lar1,lar2);
    }
}


int main()
{
    cin>>n;
    tree.resize(n);
    been.resize(n);
    visited.resize(n);
    bool linea=true;
    for(int i=0;i<n-1;i++)
    {
        cin>>a>>b;
        tree[a-1].push_back(b-1);
        tree[b-1].push_back(a-1);
        if(abs(a-b)!=1) linea=false; // :(
    }
    //if(n==3 || n==4) return cout<<1<<endl,0;
    int remain=n;
    if(linea){
        if(n%2==0)n--;
        cout<<n-2<<endl;
        return 0;
    }
    for(int i=0;i<n;i++)if(tree[i].size()==1) {
        leaf.push(i);
        deep.push(1);
        been[i]=-1;
        visited[i]=true;
        remain--;
    }
    while(leaf.size())
    {
        a = leaf.front();
        b = deep.front();
        deep.pop();
        if(remain==0 && b == deep.back()) candidates.push_back(a);
        //cout<<a+1<<" "<<b<<endl;
        been[a]++;
        leaf.pop();
        if(tree[a].size()-been[a]==1)
        {
            for(auto it : tree[a])
            {
                if(!visited[it])
                {
                    leaf.push(it);
                    deep.push(b+1);
                    visited[it]=true;
                    remain--;
                }
            }
        }
    }
    int res=n-1;
    for(auto it : candidates)
    {
        //cout<<""<<it+1<<endl;
        dfs(it);
        //for(auto nei : tree[it]){for(auto elem : mapa[nei]) cout<<elem<<" ";cout<<endl;}
        //cout<<lar1<<" "<<lar2<<endl;
        int cnt1=0,cnt2=0;
        for(int i=0;i<n;i++)
        {
            if(been[i]==lar1)cnt1++;
            if(been[i]==lar2)cnt2++;
            //cout<<been[i]<<" ";
        }
//cout<<cnt1<<" "<<cnt2<<endl;
        //cout<<endl;
        if(lar1==lar2)res = min(res, min(cnt1/2+n%2,lar1+lar2) );
        else res = min(res, min((cnt1+cnt2)/2+n%2,lar1+lar2) );
    }
    cout<<res<<endl;
    return 0;
    //cout<<a<<endl;


}