#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
template<class T> bool chmin(T& a, const T& b) {return a>b? a=b, true:false;}
template<class T> bool chmax(T& a, const T& b) {return a<b? a=b, true:false;}
const int mod = 1e9+7, N = 2e5+5;
inline int msb(int val){return sizeof(int)*8-__builtin_clzll(val)-1;}
int a[N], n, m, k;
int b[N];
void solve(int test_case){
	int i, j;
	cin >> n;
	for(i=0;i<n;i++)
		cin >> a[i] >> b[i];
		
	int ans = mod;
	for(i=0;i<n;i++){
		chmin(ans, a[i] + b[i]);
	}
	for(i=0;i<n;i++){
		int al = a[i];
		int mn = mod;
		for(j=0;j<n;j++){
			if(i == j)continue;
			chmin(mn, b[j]);
		}
		chmin(ans, max(al,mn));
	}
	cout << ans << '\n';
	return;
}

signed main(){
	FASTIO;
//~ #define MULTITEST 1
#if MULTITEST
	int _T;
	cin >> _T;
	for(int T_CASE = 1; T_CASE <= _T; T_CASE++)
		solve(T_CASE);
#else
	solve(1);
#endif
	return 0;
}




#include<bits/stdc++.h>
using namespace std;
using I=int;
const int M = 1<<18;

I n,s,t,F[M],p[M],E[M],d[M],D;
vector<I>G[M];
void dfs(I x,I f,I&s) {
	F[x]=f;d[x]=d[f]+1;if(d[x]>d[s])s=x;
	for (I&y:G[x])if(y^f)dfs(y,x,s);
}

void dfs2(I u,I f) {
	E[u]=++D;
	for(I&v:G[u])if(v!=f&&!p[v])dfs2(v,u);
	for(I&v:G[u])if(v!=f&&p[v])dfs2(v,u);
	++D;
}

I main() {
	cin>>n;
	for(I u,v,i=1;i<n;++i) {
		cin>>u>>v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1,0,s),dfs(s,0,t);
	for(I u=t;u;u=F[u])p[u]=1;
	dfs2(s,0);
	for(I i=1;i<=n;++i)cout<<E[i]<<" \n"[i==n];
}