#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define el <<"\n"
#define pll pair< ll, ll >
#define pb push_back
using namespace std;
long long n, d[100009];
vector< ll > a[100009];
void dfs(ll k, ll cha){
bool kt = 0;
ll res = -2, sl;
for(ll i : a[k])
if(i != cha){
kt = 1;
dfs(i, k);
if(res == d[i])
sl++;
if(res < d[i]){
res = d[i];
sl = 1;
}
}
if(!kt){
d[k] = 0;
return;
}
if(sl > 1)
d[k] = res + 1;
else
d[k] = res;
}
void lm(){
ll i;
dfs(1, 0);
cout << d[1] el;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
freopen("PINETREE.inp","r",stdin);
freopen("PINETREE.out","w",stdout);
///------- MINH KHANG ----------///
ll i;
cin >> n;
for(i = 1; i < n ;++i){
ll x, y;
cin >> x >> y;
a[x].pb(y);
a[y].pb(x);
}
lm();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgZmkgZmlyc3QKI2RlZmluZSBzZSBzZWNvbmQKI2RlZmluZSBsbCBsb25nIGxvbmcKI2RlZmluZSBlbCA8PCJcbiIKI2RlZmluZSBwbGwgcGFpcjwgbGwsIGxsID4KI2RlZmluZSBwYiBwdXNoX2JhY2sKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKbG9uZyBsb25nIG4sIGRbMTAwMDA5XTsKdmVjdG9yPCBsbCA+IGFbMTAwMDA5XTsKdm9pZCBkZnMobGwgaywgbGwgY2hhKXsKICAgIGJvb2wga3QgPSAwOwogICAgbGwgcmVzID0gLTIsIHNsOwogICAgZm9yKGxsIGkgOiBhW2tdKQogICAgICAgIGlmKGkgIT0gY2hhKXsKICAgICAgICAgICAga3QgPSAxOwogICAgICAgICAgICBkZnMoaSwgayk7CiAgICAgICAgICAgIGlmKHJlcyA9PSBkW2ldKQogICAgICAgICAgICAgICAgc2wrKzsKICAgICAgICAgICAgaWYocmVzIDwgZFtpXSl7CiAgICAgICAgICAgICAgICByZXMgPSBkW2ldOwogICAgICAgICAgICAgICAgc2wgPSAxOwoKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIGlmKCFrdCl7CiAgICAgICAgZFtrXSA9IDA7CiAgICAgICAgcmV0dXJuOwogICAgfQogICAgaWYoc2wgPiAxKQogICAgICAgIGRba10gPSByZXMgKyAxOwogICAgZWxzZQogICAgICAgIGRba10gPSByZXM7Cgp9CnZvaWQgbG0oKXsKICAgIGxsIGk7CiAgICBkZnMoMSwgMCk7CiAgICBjb3V0IDw8IGRbMV0gZWw7Cn0KaW50IG1haW4oKQp7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKICAgIGNpbi50aWUoTlVMTCk7Y291dC50aWUoTlVMTCk7CgogICAgZnJlb3BlbigiUElORVRSRUUuaW5wIiwiciIsc3RkaW4pOwogICAgZnJlb3BlbigiUElORVRSRUUub3V0IiwidyIsc3Rkb3V0KTsKLy8vLS0tLS0tLSBNSU5IIEtIQU5HIC0tLS0tLS0tLS0vLy8KICAgIGxsIGk7CiAgICBjaW4gPj4gbjsKICAgIGZvcihpID0gMTsgaSA8IG4gOysraSl7CiAgICAgICAgbGwgeCwgeTsKICAgICAgICBjaW4gPj4geCA+PiB5OwogICAgICAgIGFbeF0ucGIoeSk7CiAgICAgICAgYVt5XS5wYih4KTsKICAgIH0KICAgIGxtKCk7CiAgICByZXR1cm4gMDsKfQo=