#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,a[100005],t=LLONG_MAX;
vector<ll> v[100005];
unordered_map<ll,ll> mp,gl;
ll res;
void dq(ll i)
{
    gl[i]=1;
    for(auto x:v[i])
    {
        res=min(res,a[x]);
        if(gl[x]==1){return;}
        gl[x]=1;
        if(mp[x]==0)
        {
            mp[x]=1;dq(x);
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(NULL);
    if(fopen("LIBRARY.INP","r"))
    {
        freopen("LIBRARY.INP","r",stdin);
        freopen("LIBRARY.OUT","w",stdout);
    }
    cin>>n>>m;
    for(ll i=1;i<=n;i++){cin>>a[i];t=min(t,a[i]);}

    for(ll i=1;i<=m;i++)
    {
        ll u,p;
        cin>>u>>p;
        v[u].push_back(p);
        v[p].push_back(u);
    }
    cout<<t;return 0;
    for(ll i=1;i<=n;i++)
    {
        if(mp[i]==0)
        {
          res=a[i];
          dq(i);
          t+=res;
        }
        for(ll j=1;j<=n;j++) gl[i]=0;
        mp[i]=1;
    }
    cout<<t;
}

