#include <iostream>
#include <vector>
#include <climits>

using namespace std;
//long int bignigga = 0;

enum Boja {
    bela, nigga, nista
};

struct Node {
    long int id;
    vector<long int> nbrs;
    vector<long int> vrednosti;
    Boja boja;
    long int parent;
};
vector<Node> nodes;
vector<Node *> researched; // izgleda da ovaj nece biti protreba
vector<Node *> toresearch;

void remover(long int id) {
    for (long int i = 0; i < toresearch.size(); i++) {
        if (toresearch[i]->id == id) {
            toresearch.erase(toresearch.begin()+i);
            break;
        }
    }
}

long int getVrednost(long int id, long int sid) {
    for (long int i = 0; i < nodes[id].nbrs.size(); i++) {
        if (nodes[id].nbrs[i] == sid) {
            return nodes[id].vrednosti[i];
        }
    }
}
long int getVrednostId(long int id, long int sid) {
    for (long int i = 0; i < nodes[id].nbrs.size(); i++) {
        if (nodes[id].nbrs[i] == sid) {
            return i;
        }
    }
}
long int getMaxEx(long int id, long int sid) {
    long int maxx = -1;
    for (long int i = 0; i < nodes[id].vrednosti.size(); i++) {
        if (nodes[id].nbrs[i] != sid) {
            long int sizee = nodes[id].vrednosti[i];
            if (sizee > maxx) maxx = sizee;
        }
    }
    return maxx;
}

long int getMax(long int id) {
    long int maxx = -1;
    for (long int i = 0; i < nodes[id].vrednosti.size(); i++) {
        long int sizee = nodes[id].vrednosti[i];
        if (sizee > maxx) maxx = sizee;
    }
    return maxx;
}

void update(long int id, long int sid) {
    // ovo znaci updatejujjuj id ali bez sid ili tako nes
    for (long int i = 0; i < nodes[sid].nbrs.size(); i++) {
        long int cid = nodes[id].nbrs[i];
        if (cid != sid && getMaxEx(cid, id) +1 > getVrednost(id, cid) ) {
            nodes[cid].vrednosti[getVrednostId(cid,id)]++;
            update(cid,id);
        }
    }
}

void research(long int id, Boja boja) {
    long int sid = nodes[id].parent;
    long int maxid = getMax(id);
    nodes[id].boja = boja;
    remover(id);
    for (long int i = 0; i < nodes[id].nbrs.size(); i++) {
        long idd = nodes[id].nbrs[i];
        if (idd != sid) {
            toresearch.push_back(&nodes[idd]);
            nodes[idd].parent=id;
            nodes[idd].vrednosti[getVrednostId(idd,id)]=maxid+1;
        }
    }
    long int sidmax = getMax(sid);
    nodes[sid].vrednosti[getVrednostId(sid,id)] = 2; // valjda je ovo tacno
    // BIG NIGGA ANNOUNCEMENT
    // sada ce se proveravati dali se trebaju updateovati vrednosti ovih sranja
    if (boja == Boja::bela) {
    for (long int i = 0; i < nodes[sid].nbrs.size(); i++) {
        long int cid = nodes[sid].nbrs[i];
        if (getMaxEx(sid, cid) +1 > getVrednost(cid, sid) ) {
            nodes[cid].vrednosti[getVrednostId(cid,sid)]++;
            //cout << "cemo da updateujemo cid, sid: " << cid << " " << sid << endl;
            update(cid,sid);
        }
    }
    }

}

void pick(Boja boja) {
    //vector<Node> &researchedd = toresearch;
    long int sid = -1;
    long int maxx = LONG_MAX;
    for (long int i = 0; i < toresearch.size(); i++) {
        long int maxy = getMax(toresearch[i]->id);
        if (maxy < maxx) {
            maxx = maxy;
            sid = toresearch[i]->id;
        }
    }
    research(sid, boja);
}


int main()
{
    //cout << "AAAAAAAAAAAAAAAAAAA" << endl;
    std::ios::sync_with_stdio(false);
    long int n;
    //cout << "ooooof" << endl;
    cin >> n;
   // cout << "aa" << endl;
    vector<long int> emptyv;
    for (long int i = 0; i < n; i++) {
        Node node = Node {i, emptyv, emptyv, Boja::nista, 0};
        nodes.push_back(node);

    }
    for (long int i = 0; i < n-1; i++) {
        long int u,v;
        //cout << "big oof" << endl;
        cin >> u >> v;
        u--;
        v--;
        nodes[u].nbrs.push_back(v);
        nodes[u].vrednosti.push_back(0);
        nodes[v].nbrs.push_back(u);
        nodes[v].vrednosti.push_back(0);
    }
    //cout << "yeet" << endl;
    long int maxnbrs = 0;
    long int snode = 0;
    for (long int i = 0; i < n; i++) {
        if (nodes[i].nbrs.size() > maxnbrs) {
            maxnbrs = nodes[i].nbrs.size();
            snode = i;
        }
    }
    //researched.push_back(&nodes[snode]);
    //nodes[snode].vrednost = 0;
    nodes[snode].boja = Boja::bela;
    research(snode, Boja::bela);
    for (long int i = 0; i < n; i++) {
        Boja boja = Boja::nigga;
        pick(boja);
        if (boja == Boja::bela) boja = Boja::nigga;
        else boja = Boja::bela;
    }
    long int rastrkanost = 0;
    for (long int i = 0; i < n; i++) {
        if (nodes[i].boja == Boja::bela) {
            long int vrd = getMax(i);
            if (vrd > rastrkanost) rastrkanost = vrd;
        }
    }
    cout << rastrkanost << endl;

    return 0;
}