#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n;
vector<llint> G[100005];
map<P, llint> mp, mp2;

void dfs(int v, int p)
{
	llint deg = 0;
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] == p) continue;
		dfs(G[v][i], v);
		deg++;
	}
	if(deg == 0){
		mp[P(p, v)] = 1;
		return;
	}
	
	llint sum = 0;
	for(int i = 0; i < G[v].size(); i++){
		int u = G[v][i];
		if(u == p) continue;
		sum += mp[P(v, u)];
	}
	mp[P(p, v)] = sum;
}

void dfs2(int v, int p)
{
	llint sum = 0;
	for(int i = 0; i < G[v].size(); i++){
		int u = G[v][i];
		sum += mp[P(v, u)];
	}
	for(int i = 0; i < G[v].size(); i++){
		int u = G[v][i];
		if(u == p) continue;
		mp[P(u, v)] = sum - mp[P(v, u)];
	}
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] == p) continue;
		dfs2(G[v][i], v);
	}
}

void calcdfs(int v, int p)
{
	llint deg = 0;
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] == p) continue;
		calcdfs(G[v][i], v);
		deg++;
	}
	if(deg <= 1){
		mp2[P(p, v)] = 1;
		for(int i = 0; i < G[v].size(); i++){
			int u = G[v][i];
			if(u == p) continue;
			mp2[P(p, v)] += mp2[P(v, u)];
		}
		return;
	}
	
	llint sum = mp[P(p, v)], mx = 0;
	for(int i = 0; i < G[v].size(); i++){
		int u = G[v][i];
		if(u == p) continue;
		mx = max(mx, sum + mp2[P(v, u)] - mp[P(v, u)]);
	}
	mp2[P(p, v)] = mx;
}

llint lmax[100005], rmax[100005];
void calcdfs2(int v, int p)
{
	llint sum = 0;
	for(int i = 0; i < G[v].size(); i++){
		int u = G[v][i];
		sum += mp[P(v, u)];
	}
	if(G[v].size() <= 1) return;
	
	if(G[v].size() == 2){
		for(int i = 0; i < G[v].size(); i++){
			int u = G[v][i];
			if(u == p) continue;
			mp2[P(u, v)] = 1 + mp2[P(v, p)];
			calcdfs2(u, v);
		}
		return;
	}
	
	llint m = G[v].size();
	lmax[0] = -inf;
	for(int i = 0; i < m; i++){
		int u = G[v][i];
		lmax[i+1] = max(lmax[i], mp2[P(v, u)] - mp[P(v, u)]);
	}
	rmax[m+1] = -inf;
	for(int i = m-1; i >= 0; i--){
		int u = G[v][i];
		rmax[i+1] = max(rmax[i+2], mp2[P(v, u)] - mp[P(v, u)]);
	}
	
	for(int i = 0; i < G[v].size(); i++){
		int u = G[v][i];
		if(u == p) continue;
		mp2[P(u, v)] = sum - mp[P(v, u)] + max(lmax[i], rmax[i+2]);
	}
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] == p) continue;
		calcdfs2(G[v][i], v);
	}
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	llint u, v;
	for(int i = 1; i <= n-1; i++){
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	
	llint root = -1;
	for(int i = 1; i <= n; i++){
		if(G[i].size() >= 3){
			root = i;
			break;
		}
	}
	if(root == -1){
		cout << n << endl;
		return 0;
	}
	
	dfs(root, -1);
	dfs2(root, -1);
	
	calcdfs(root, -1);
	calcdfs2(root, -1);
	
	/*for(auto it = mp2.begin(); it != mp2.end(); it++){
		cout << it->first.first << " " << it->first.second << " " << it->second << endl;
	}*/
	
	llint ans = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < G[i].size(); j++){
			ans = max(ans, mp2[P(i, G[i][j])]+1);
		}
	}
	cout << ans << endl;
	
	return 0;
}