#define REP(a,b) for(int a=0; a<(b); ++a)
#define REP2(a,b) for(int a=1; a<=(b); ++a)
#define FWD(a,b,c) for(int a=(b); a<(c); ++a)
#define BCK(a,b,c) for(int a=(b)-1; a>=(c); --a)
#define BCK2(a,b,c) for(int a=(b); a>(c); --a)
#define FWDS(a,b,c,d) for(int a=(b); a<(c); a+=d)
#define ALL(a) (a).begin(), (a).end()
#define SIZE(a) ((int)(a).size())
#define VAR(x) #x ": " << x << " "
#define FILL(x,y) memset(x,y,sizeof(x))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);
#define x first
#define y second
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define l(n) (n<<1)
#define r(n) ((n<<1)+1)
#define f(n) (n>>1)
#define lsb(a) (a&-a)
#include<vector>
#include<stack>
#include<string.h>
#include<queue>
#include<algorithm>
using namespace std;
#ifndef ONLINE_JUDGE
#include<fstream>
ifstream cin("darb.in");
ofstream cout("darb.out");
#else
#include<iostream>
#endif
const int NMAX = 100000+69;
const int PMAX = 1015;
const int INF = 1 << 31;
const int dx[] = {0, 0, -1, 1}; //1,1,-1,1};
const int dy[] = {-1, 1, 0, 0}; //1,-1,1,-1};
typedef long long LL;
typedef pair<int, int> PII;
typedef long double K;
typedef pair<K, K> PKK;
typedef vector<int> VI;
VI G[NMAX];
int q[NMAX],c,v;
bool viz[NMAX];
int d[NMAX];
int a,b,n;
int i,sol,solv;
void bfs(int node)
{
c=0; v=0;
FILL(viz,0);
FILL(d,0);
q[v++]=node;
while(c<v){
i=q[c++];
REP(j,G[i].size())
if(!viz[G[i][j]])
{
q[v++]=G[i][j];
viz[G[i][j]]++;
d[G[i][j]]=d[i]+1;
if(d[G[i][j]]>sol)
sol=d[G[i][j]], solv=G[i][j];
}
}
}
int main() {
FAST;
cin>>n;
REP(i,n-1)
{
cin>>a>>b;
G[b].pb(a);
G[a].pb(b);
}
bfs(1);
bfs(solv);
cout<<sol+1;
return 0;
}