#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool visited[100005];
bool izabrani[100005];
int level[100005];
bool bfs[100005];
bool bfs2[100005];


main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n; cin >> n;
list <int> adj[n];
pair <int,int> indexi[n];
for (int i=0; i<n; i++)
{
    indexi[i].second=i;
    indexi[i].first=0;
}

for (int i=0; i<n-1; i++)
{
    int a,b; cin >> a >> b;
    a--; b--;
    if (a>b); swap(a,b);
    adj[a].push_back(b);
    adj[b].push_back(a);
    indexi[a].first+=1;
    indexi[b].first+=1;
}
int pocetni;
int mx=0;
for (int i=0; i<n; i++)
    if (indexi[i].first>mx) { mx=indexi[i].first; pocetni=indexi[i].second;}

int ct=0;
list <int> q;
q.push_back(pocetni);

while (ct<(n/2+(n%2)))
{

int cur=q.front();
q.pop_front();
visited[cur]=true;
izabrani[cur]=true;
for (auto it=adj[cur].begin(); it!=adj[cur].end(); ++it)
{
    if (!visited[*it])
    {
       visited[*it]=true;
       q.push_back(*it);
    }
}
ct++;
}

list <int> _q;
_q.push_back(pocetni);
int last;

while (_q.size())
 {
    int cur=_q.front();
    last=cur;
    _q.pop_front();
    bfs[cur]=true;
    for (auto it=adj[cur].begin(); it!=adj[cur].end(); ++it)
  {
    if (!bfs[*it] && izabrani[*it])
    {
       bfs[*it]=true;
       _q.push_back(*it);
    }

  }
 }

list <int> __q;
__q.push_back(last);
level[last]=0;
int sol=last;

while (__q.size())
 {
    int cur=__q.front();
    __q.pop_front();
    bfs2[cur]=true;
    for (auto it=adj[cur].begin(); it!=adj[cur].end(); ++it)
  {
    if (!bfs2[*it] && izabrani[*it])
    {
       sol=*it;
       bfs2[*it]=true;
       __q.push_back(*it);
       level[*it]=level[cur]+1;
    }

  }
 }
  cout << level[sol];
}