#include <bits/stdc++.h>
#define ll long long
#define MAXN 200010
using namespace std;
ll a[MAXN];
vector<ll> G[MAXN];
int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll n,u,v;
    bool one=true;
    cin >> n;
    for (ll i=1;i<=n;i++)
        cin >> a[i];
    for (ll i=1;i<n;i++)
    {
        cin >> u >> v;
        if (u!=1 && v!=1)
            one=false;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    if (one)
    {
        if (n==2)
            cout << min(a[1],a[2]) << "\n";
        else
            cout << a[1] << "\n";
        return 0;
    }
    return 0;
}