#include<bitsdc++.h>
using namespace std;
int ans,n,m,a[100005],in[100005],x[100005],y[100005];
struct edge{int to,next;
}e[100005];
priority_queue<int>q;
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i)scanf("%d",&a[i]);
for(int i=1;i<=m;++i)
{
scanf("%d%d",&x[i],&y[i]);
in[x[i]]++;in[y[i]]++;
}
for(int i=1;i<=n;++i)if(in[i]!=1)ans=max(ans,a[i]);
for(int i=1;i<=n;++i)
{
if(in[i]==1)q.push(a[i]);
}
if(!q.empty())
{
int res=1061109567;
res=min(res,q.top());q.pop();
res=min(res,q.top());q.pop();
ans=max(ans,res);
}
printf("%d\n",ans);
}