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

const int N = 1e5 + 10;
int a[N];

pair<set<int>, int> g[N];
bool m[N];
bool m2[N];
int dist1[N];
void bfs (int start) {
    queue<pair<int, int>> q;
    q.push({start, 0});
    m[start] = 1; 
    bool p = 0;
    while(!q.empty()) {
        int u = q.front().first;
        int dis = q.front().second;
        q.pop();
        g[u].second = p;
        dist1[u] = dis;
        p = !p;
        for(int x : g[u].first) {
            if(!m[x]) {
                m[x] = 1;
                q.push({x, dis + 1});
            }
        }
    }
}

int sol(int start) {
    int ret = 0;
    queue<pair<int, int>> q;
    q.push({start, 0});
    m2[start] = 1;
    while(!q.empty()) {
        int u = q.front().first;
        int dis = q.front().second;
        q.pop();
        for(int x : g[u].first) {
            if(!m2[x]) {
                m2[x] = 1;
                q.push({x, dis + 1});
                if(g[x].second == 0) ret = max(ret, dis + 1);
            }
        }
    }
    return ret;
}

int main () {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 0 ; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        g[u].first.insert(v);
        g[v].first.insert(u);
        a[u]++;
        a[v]++;
    }

    // for(int i = 1 ; i <= n ; i++) cout << i << " : " << a[i] << "\n"; 
    int start = max_element(a + 1, a + n) - a; 
    // cout << start << "\n";

    bfs(start);
    // for(int i = 1 ; i <= n ; i++) {
    //     cout << i << " : " << g[i].second << " " << dist1[i] << "\n"; 
    // }

    int longest = 0;
    int ind = 0;
    for (int i = 1 ; i <=n ; i++) {
        if(g[i].second == 0) {
            if(dist1[i] > longest) {
                longest = dist1[i];
                ind = i;
            }
        }
    }
    // cout << ind << "\n";

    cout << sol(ind) << "\n";

    return 0;
}