#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template<typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll           long long
#define rep(i,j,n)   for(ll i=j;i<n;i++)
#define _rep(i,n)   for(ll i=n-1;i>=0;i--)
#define vec          vector<ll>
#define pb           push_back    
#define eb           emplace_back
#define pairs        pair<ll,ll>
#define f            first
#define s            second
#define all(v)       v.begin(),v.end()
#define srt(v)       sort(v.begin(),v.end())
#define mem(a,b)     memset(a,b,sizeof(a))
#define fast         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(a)        (int)a.size()
const int N = 21;

ll n, a[N];
ll ans = 1e18;

vec v;
void solve(ll i, ll val, ll xors) {
	if(i == n) {
		
		ll temp = 0;
		
		ans = min(ans, xors^val);
		return;
	}
	
	solve(i+1, val|a[i], xors);
	
	solve(i+1, a[i], xors^val);
}

int Main()
{
	cin>>n;
	
	rep(i,0,n) {
		cin>>a[i];
	}
	
	solve(0, 0, 0);
	
	cout<<ans;
	return 0;
}
 
int main()
{
	  int queries=1; 
	  // cin>>queries;
	  while(queries--)
	  {
	    Main();
	  }
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unordered_set>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define P pair<ll, ll>
using namespace std;

int n;
vector<vector<int> > to;
vector<int> c, ans;
multiset<int> ms;

void dfs(int now = 0, int p = -1){
  for(auto& next: to[now]){
    if(next == p) continue;
    if(ms.find(c[next]) == ms.end()) ans.push_back(next);
    ms.insert(c[next]);
    dfs(next, now);
    ms.erase(ms.find(c[next]));
  }
}

int main(){
  cin >> n;
  c.resize(n);
  to.resize(n);
  rep(i, n) cin >> c[i];
  rep(i, n-1){
    int a, b; cin >> a >> b;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ms.insert(c[0]);
  ans.push_back(0);
  dfs();
  sort(ans.begin(), ans.end());
  for(auto& e: ans){
    cout << e+1 << endl;
  }
  return 0;
}
