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

/*^ debug  */

template <typename A, typename B> string to_string(pair<A, B> p);
template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
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;
}
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) { res += static_cast<char>('0' + v[i]); }
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) { res += ", "; }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; }
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

/*  debug $*/

/*^ generic definitions  */

template<typename F>
struct _RecurFun : F {
  _RecurFun(F&& f) : F(forward<F>(f)) {}
  template<typename... Args>
  decltype(auto) operator()(Args&&... args) const { return F::operator()(*this, forward<Args>(args)...); }
};
template<typename F>
decltype(auto) RecurFun(F&& f) { return _RecurFun<F> { forward<F>(f) }; }

template<typename D, typename R>
vector<R> maps(const vector<D> &&d, function<R(D)> f) {
  vector<R> r(d.size());
  for (int i = 0; i < (int) d.size(); ++i) r[i] = f(d[i]);
  return r;
}

/*  generic definitions $*/

int main() {
  ios::sync_with_stdio(false);

  int N; { cin >> N; }

  vector<int> C(N); {
    for (int i = 0; i < N; ++i) cin >> C[i];
  }

  vector<vector<int>> G(N); {
    for (int i = 0; i + 1 < N; ++i) {
      int u, v; { cin >> u >> v; --u, --v; }
      G[u].push_back(v);
      G[v].push_back(u);
    }
  }

  vector<int> res;
  set<int> bag;
  function<void(int, int)> dfs = [&](int u, int fa) {
    for (int v : G[u]) if (v != fa) {
      bool flag = false;
      if (!bag.count(C[v])) flag = true, bag.insert(C[v]), res.push_back(v);
      dfs(v, u);
      if (flag) bag.erase(C[v]);
    }
  };

  res.push_back(0);
  bag.insert(C[0]);
  dfs(0, -1);

  sort(res.begin(), res.end());
  for (int u : res) cout << u+1 << "\n";
}


#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
#pragma GCC target ("avx2,avx,fma")
typedef long long int ll;
//#define int long long int
typedef long double db;
typedef pair <int,int> ii ;
typedef vector < int > vi ;
typedef vector < ii > vii ;
#define rep(i,n)                   for(int i = 0 ; i < n ; i++)
#define repu(i,a,b)                for(int i = a ; i <= b ; i++) 
#define repd(i,b,a)                for(int i = b ; i >= a ; i--)
#define pb push_back
#define fi first
#define se second
#define all(p)                p.begin(),p.end()
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Endl endl
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (int)r;}
template <class T>inline void sary(T st, T nd){while(st<nd)cin>>*st++;/*sf("%d", st++);*/}
int mod=998244353;
inline ll mul(ll a, ll b){return ((a%mod)*(b%mod))%mod;}
inline ll add(ll a, ll b){return ((a%mod)+(b%mod))%mod;}
inline ll sub(ll a, ll b){return ((a%mod)-(b%mod)+mod)%mod;}
inline ll divi(ll a, ll b) { return (500000004*(a%mod))%mod; }
const int N= 5002;

int sum(int n) {
    int s=0;
    while(n) {
        s+=n%10; n/=10;
    }
    return s;

}

void solve() {
  int a,  b; cin>>a>>b;
  cout<<max(sum(a),sum(b));
}   
 
int32_t main() {
  IOS
  int t=1;
  //cin>>t;
  #ifndef ONLINE_JUDGE
    clock_t clk = clock();
    #endif
  while(t--) solve();
  #ifndef ONLINE_JUDGE
  cerr << "\nTime (in ms): " << double(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';
  #endif
}