#include <bits/stdc++.h>

using namespace std;

vector<int> a[100005];
bool posecen[100005];

int BFS(vector<int> adj[], int src, int dest, int v, int dist[])
{
    list<int> queue;

    for (int i = 0; i < v; i++) {
        posecen[i] = false;
        dist[i] = INT_MAX;
    }

    posecen[src] = true;
    dist[src] = 0;
    queue.push_back(src);

    while (!queue.empty()) {
        int u = queue.front();
        queue.pop_front();
        for (int i = 0; i < adj[u].size(); i++) {
            if (posecen[adj[u][i]] == false) {
                posecen[adj[u][i]] = true;
                dist[adj[u][i]] = dist[u] + 1;
                queue.push_back(adj[u][i]);
                if (adj[u][i] == dest)
                   return dist[dest];
            }
        }
    }
    return -1;
}

void Resi(int N){
    int cvor1=-1;
    int cvor2=-1;
    for(int i=0;i<N;i++){
        if(a[i].size()!=1){
            int br=0;
            bool moze=true;
            for(int j=0;j<a[i].size();j++){
                if(a[a[i][j]].size()>1)
                    br++;
                if(br>1)
                    moze=false;
            }
            if(moze){
                if(cvor1==-1)
                    cvor1=i;
                else
                    cvor2=i;
            }
        }
    }
    int dist[N];
    int d=BFS(a,cvor1,cvor2,N,dist);
    if(a[cvor1].size()>2&&a[cvor2].size()>2)
        cout<<d+2;
    else if(a[cvor1].size()==2&&a[cvor2].size()==2)
        cout<<d+1;
    else if((a[cvor1].size()==2&&a[cvor2].size()>2)||(a[cvor1].size()>2&&a[cvor2].size()==2)){
        if(N%2==0)
            cout<<d+1;
        else
            cout<<d+2;
    }
}

int main()
{
    int N;
    cin>>N;

    bool redom=true;
    bool centralno=false;
    for(int i=0;i<N-1;i++){
        posecen[i]=false;
        int u,v;
        cin>>u>>v;
        a[u-1].push_back(v-1);
        a[v-1].push_back(u-1);
        if(abs(u-v)!=1)
            redom=false;
    }
    posecen[N-1]=false;
    if(N==3)
        cout<<1;
    else if(redom){
        if(N%2==0)
            cout<<(N-2)/2;
        else
            cout<<(N-1)/2;
    }
    else{
        for(int i=0;i<N;i++){
            if(a[i].size()==N-1){
                centralno=true;
            }
        }
        if(centralno)
            cout<<2;
        else{
            Resi(N);
        }
    }

    return 0;
}