#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int,int> p;
const int N = 1e5+45;

int n;
vector <int> g[N];
bool visited[N];
int dist[N];

void ocisti(){
    for(int i = 1; i <= n; i++){
        visited[i] = 0;
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int i = 1; i < n; i++){
        int x,y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    queue <p> q;
    q.push(p(1,0));
    visited[1] = 1;
    int u = 0,maxi = 0;
    while(!q.empty()){
        p x = q.front();
        if(x.second > maxi){
            maxi = x.second;
            u = x.first;
        }
        q.pop();
        for(auto f : g[x.first]){
            if(!visited[f]){
                visited[f] = 1;
                q.push(p(f,x.second+1));
            }
        }
    }
    ocisti();
    int v = 0;
    maxi = 0;
    q.push(p(u,0));
    visited[u] = 1;
    while(!q.empty()){
        p x = q.front();
        if(x.second > maxi){
            maxi = x.second;
            v = x.first;
        }
        q.pop();
        for(auto f : g[x.first]){
            if(!visited[f]){
                visited[f] = 1;
                q.push(p(f,x.second+1));
            }
        }
    }
    int d = maxi;
    ocisti();
    //cout << d << " " << u << " " << v << endl;
    q.push(p(u,0));
    visited[u] = 1;
    while(!q.empty()){
        p x = q.front();
        dist[x.first] = x.second;
        q.pop();
        for(auto f : g[x.first]){
            if(!visited[f]){
                visited[f] = 1;
                q.push(p(f,x.second+1));
            }
        }
    }
    bool ima = 0;
    for(int i = 1; i <= n; i++){
        if(dist[i] == d && i != v){
            ima = 1;
            break;
        }
    }
    if(d%2 == 0){ /// centrirano
        if(!ima){
            cout << d-1 << endl;
        }
        else{
            cout << d << endl;
        }
    }
    else{
        if(!ima){
            cout << d-2 << endl;
        }
        else{
            cout << d-1 << endl;
        }
    }
}