#include <bits/stdc++.h>
using namespace std;
constexpr int NMax=100005;
ifstream fin("darb.in");
ofstream fout("darb.out");
int N;
vector<int> G[NMax];
int length,lastNode;
void DFS(int node, int father, int level)
{
if(level>length)
length=level, lastNode=node;
for(auto child : G[node])
if(child!=father)
DFS(child,node,level+1);
}
int main()
{
fin>>N;
for(int i=1;i<N;i++)
{
int x,y;
fin>>x>>y;
G[x].push_back(y);
G[y].push_back(x);
}
DFS(1,0,1);
length=0; DFS(lastNode,0,1);
fout<<length;
return 0;
}