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

#ifdef LOCAL
#include "../debug.h"
#else
#define debug(x...) 141
#endif
#define forn(i,x,n) for(int i = x; i < n; ++i)
#define forit(it, m) for(auto it = m.begin(); it!=m.end(); ++it)
typedef long long ll;

vector<vector<int>> adj;
vector<int> vis, col, good;
multiset<int> seen;

void dfs(int u){
	vis[u]=true;
	if(!seen.count(col[u]))
		good.push_back(u+1);
	seen.insert(col[u]);
	for(auto v:adj[u])
		if(!vis[v])
			dfs(v);
	seen.erase(seen.find(col[u]));
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,x,y;

    cin>>n;
    adj.assign(n,vector<int>());
    vis.assign(n,false);
    col.assign(n,0);
    forn(i,0,n)
    	cin>>col[i];
    forn(i,0,n-1)
    	cin>>x>>y,
    	adj[x-1].push_back(y-1),
    	adj[y-1].push_back(x-1);

    dfs(0);
    sort(good.begin(),good.end());

    for(auto x:good)
    	cout<<x<<'\n';
    
    return 0;
}
#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
    #include <atcoder/all>
    using namespace atcoder;
#endif
using namespace std;

typedef pair<int, int> P;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 1; i < (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define mp make_pair
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll B, C;
  cin >> B >> C;
  ll a1 = B-C/2;
  ll a2 = B+(C-2)/2;
  ll a3 = -B-(C-1)/2;
  ll a4 = -B+(C-1)/2;
//   cout << a1 << ' ' << a2 << ' ' << a3 << ' ' << a4 << endl;
  if (min(a1, a2) > max(a3, a4) || min(a3, a4) > max(a1, a2)) {
      cout << max(a1, a2)-min(a1, a2)+1+max(a3, a4)-min(a3, a4)+1 << endl;
  } else {
      cout << max({a1, a2, a3, a4}) - min({a1, a2, a3, a4})+1 << endl;
  }
}
