#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define srt(v) sort(v.begin(),v.end())
#define srtg(v,int) sort(v.begin(),v.end(),greater<int>())
#define lb(a,v) lower_bound(v.begin(),v.end(),a)
#define ub(a,v) upper_bound(v.begin(),v.end(),a)
#define fnd(a,v) find(v.begin(),v.end(),a)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef string str;
void rastojanje(int cvor,int dis,vector<vector<int> > &g,vector<bool> &bio,int &naj,int &ras){
    if(bio[cvor]) return;
    bio[cvor]=true;
    if(dis>ras){
        ras=dis;
        naj=cvor;
    }
    for(int i:g[cvor]){
        if(!bio[i]){
            rastojanje(i,dis+1,g,bio,naj,ras);
        }
    }
}
int main()
{
    //valjda ubode koji poen :)
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<vector<int> > g(n+1);
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        g[a].pb(b);
        g[b].pb(a);
    }
    vector<bool> bio(n+1,false);
    int pom1=0;
    int pom2=0;
    rastojanje(1,0,g,bio,pom1,pom2);
  //  cout<<pom1<<" "<<pom2;
    pom2=0;
    int naj=0;
    vector<bool> bio2(n+1,false);
    rastojanje(pom1,0,g,bio2,pom2,naj);
    cout<<(n%2==0 ? naj-2:naj);
    return 0;
}