#include"bits/stdc++.h"
using namespace std;

#define MAX 100002

int n;

vector<int> v[MAX];

int dp[MAX];

int ans;
int ans2;

int leaf[MAX];

int cer;

int wa;


inline void dfs(int b,int pr){
	vector<int> ret;
	for(int go:v[b]){
		if(go==pr)continue;
		dfs(go,b);
		leaf[b]+=leaf[go];
		ret.push_back(dp[go]);
	}
	leaf[b]+=(v[b].size()==1);
	sort(ret.begin(),ret.end(),greater<int>());
	while(ret.size()<=2)ret.push_back(0);
	if(true){
		wa=max(wa,(v[b].size()==2)+ret[0]+ret[1]);
	}
	dp[b]=max(dp[b],(v[b].size()==2)+ret[0]);
	return;
}

int main(){
	cin>>n;
	for(int i=1;i<n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		a--;
		b--;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	dfs(0,-1);
	dp[0]=max(dp[0],wa);
	cout<<dp[0]+leaf[0]<<endl;
	return 0;
}
