#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<pair<ll,ll> > vpl;//追加はmake_pairを使う
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqg; //昇順のPriority queue
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define all(v) v.begin(), v.end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0;}
#define dbl(i) fixed << setprecision(15) << i << endl;
#define GET_VARIABLE_NAME(Variable) (#Variable)
#define dbc(a) cout << GET_VARIABLE_NAME(a) << "=" << a << endl;
#define vsum(v) accumulate(all(v), 0);
#define rsort(v) sort(v.begin(),v.end(),greater<ll>());
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }
    // 素数である
    return true;
}
vector<ll> enum_divisors(ll N) {//約数列挙
    vector<ll> res;
    for (ll i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // 重複しないならば i の相方である N/i も push
            if (N/i != i) res.push_back(N/i);
        }
    }
    // 小さい順に並び替える
    sort(res.begin(), res.end());
    return res;
}
vector<pair<long long, long long> > prime_factorize(long long N) {//因数分解
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        pair <ll,ll> push;
        push.first=a;
        push.second=ex;
        res.push_back(push);
    }

    // 最後に残った数について
    if (N != 1){
        pair <ll,ll> push;
        push.first=N;
        push.second=1;
        res.push_back(push);
    }
    return res;
}
ll gcd(ll a, ll b){//最大公約数
        if (a%b == 0){
            return(b);
        }else{
            return(gcd(b, a%b));
        }
    }
ll lcm(ll a, ll b){//最小公倍数
   return a / gcd(a, b) * b;
}
ll comb(ll n, ll r) {
if(n<r) return 0;
  if ( r * 2 > n ) r = n - r;
  ll dividend = 1;
  ll divisor  = 1;
  for ( ll i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}
void exgcd(ll a,ll b,ll &x,ll &y)
{
	if(b==0){ x=1;y=0; }
	else{ exgcd(b,a%b,y,x);y-=a/b*x; }
}
ll inv(ll a,ll Mod){//modにおけるaの逆元
	ll x,y;
	exgcd(a,Mod,x,y);
	return (x%Mod+Mod)%Mod;
}
ll RepeatSquaring(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t = RepeatSquaring(N, P/2, M);
        return t*t % M;
    }
    return N * RepeatSquaring(N, P-1, M);
}
ll rui(ll a,ll n){
    ll x=1;
    while(n>0){
        if(n&1){
            x=x*a;
        }
        a=a*a;
        n>>=1;
    }
    return x;
}
ll f(ll n, vector <string>s){
    if(s[n]=="OR"){
        if(n==0)return 3;
        return rui(2,n+1)+f(n-1,s);
    }else{
        if(n==0)return 1;
        return f(n-1,s);
    }
}
string toBinary(int n)
{
    string r;
    while (n != 0){
        r += ( n % 2 == 0 ? "0" : "1" );
        n /= 2;
    }
    return r;
}

int main(){
    ll n,x;
    cin>>n>>x;
    rep(i,n){
        ll t;
        cin>>t;
        if(t!=x)cout<<t<<" ";
    }
    cout<<endl;
}
#include <bits/stdc++.h>

#define ln                 '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = 2e5;
int n, dfn[nsz + 5];
vector<int> g[nsz + 5];

void bfs(int s, int *d) {
	static int q[nsz + 5];
	int ql = 0, qr = 0;
	cont (u, n) d[u] = -1;
	for (q[qr++] = s, d[s] = 0; ql != qr;) {
		int u = q[ql++];
		for (int v : g[u]) if (d[v] == -1) q[qr++] = v, d[v] = d[u] + 1;
	}
}

void inline find_diameter(vector<int> &nd) {
	static int d[nsz + 5];
	int u = 1, v = 1;
	bfs(1, d);
	cont (v, n) if (d[v] > d[u]) u = v;
	bfs(u, d);
	cont (u, n) if (d[u] > d[v]) v = u;
	for (int w = v; w != u;) {
		nd.push_back(w);
		for (int v : g[w]) if (d[v] == d[w] - 1) {
			w = v;
			break;
		}
	}
	nd.push_back(u);
}

void dfs(int u, int &t, int p1 = -1, int p2 = -1) {
	t += 1;
	dfn[u] = t;
	for (int v : g[u]) if (v != p1 && v != p2) dfs(v, t, u);
	t += 1;
}

void inline solve() {
	vector<int> nd;
	find_diameter(nd);
	int t = 0;
	loop (i, nd.size()) {
		int p1 = i - 1 >= 0 ? nd[i - 1] : -1;
		int p2 = i + 1 < nd.size() ? nd[i + 1] : -1;
		dfs(nd[i], t, p1, p2);
		t -= 1;
	}
}

int main() {
	scanf("%d", &n);
	cont (i, n - 1) {
		int u, v;
		scanf("%d%d", &u, &v);
		g[u].push_back(v), g[v].push_back(u);
	}
	solve();
	cont (u, n) printf("%d%c", dfn[u], "\n "[u < n]);
}