#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int, int> >
#define vpll vector <pair <long long, long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define vb vector <bool>
#define vvb vector <vb>
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MANX MAXN
#define itn int
#define dbg(x); {cout << #x << "=" << x << ", ";}
#define in(x); { for (auto &to : x) cin >> to;}
#define out(x); { for (auto &to : x) cout << to << " "; cout << '\n'; }

template<class T>
bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }

template<class T>
bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const ll INFLL = 1e18;
const int MAXN = 1e6 + 100;
const ll INF = 1e9;
const int mod1 = 1e9 + 7;
const int mod2 = 1e9 + 21;

void solve() {
    int x, y;
    cin >> x >> y;
    cout << (x == y ? x : 3 ^ x ^ y) << '\n';
}

int main() {
#ifdef Mip182
    freopen("a.in", "r", stdin);
#else
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int _t;
    _t = 1;
//    cin>>_t;
    while (_t--)
        solve();
#ifdef Mip182
    cout << '\n' << "Time : " << (double) (clock()) / CLOCKS_PER_SEC << '\n';
#endif
}

#include<bits/stdc++.h>
using namespace std;
#ifdef local
string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
typedef long long ll;
#define f(i, l, r) for(int i=l;i<=r;i++)
#define rf(i, r, l) for(int i=r;i>=l;--i)
#define all(x) x.begin(),x.end()
const int N = 2e5+10, mod = 1e9+7;
ll power(ll a, ll b) {ll res = 1;while (b) {if (b & 1)res = res * a % mod;a = a * a % mod;b >>= 1;}return res;}
ll INV(ll a){return power(a,mod-2);}
mt19937 Rand(123456);
int Range(int l,int r){
    return l+Rand()%(r-l+1);
}
vector<int> g[N];
int dis[N];
int T,D;
int mx_dep[N],ans[N];
void dfs(int u,int f){
    if(dis[u]>D){
        D=dis[u];T=u;
    }
    mx_dep[u]=dis[u];
    for(int v:g[u])if(v!=f){
        dis[v]=dis[u]+1;
        dfs(v,u);
        mx_dep[u]=max(mx_dep[u],mx_dep[v]);
    }
}
int sz[N];
int step;
void dfs2(int u,int f){
    debug(u,dis[u]);
    sort(all(g[u]),[&](int l,int r){
       return  mx_dep[l]<mx_dep[r];
    });
    ans[u]=++step;
    for(int v:g[u])if(v!=f){
        dfs2(v,u);
    }
    step++;
}
int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifdef local
    freopen("../in.txt", "r", stdin);
#endif
    int n;cin>>n;
    f(i,1,n-1){
        int u,v;cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    D=-1;dfs(1,0);
    D=-1;int k=T;dis[k]=1;dfs(T,0);
    dfs2(k,0);
    f(i,1,n)cout<<ans[i]<<" ";
}