#include<iostream>
#include<algorithm>
using namespace std;
int n,m,a[100],x[100][100],p,q,b[12]={0,1,2,3,4,5,6,7,8,9,10,11},v,w;
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=m;i++){
cin>>p>>q;
x[p][q]=1;
x[q][p]=1;
}
do{
v=a[b[0]+1];
for(int i=1;i<n;i++){
if(x[b[i-1]+1][b[i]+1]==1){
v+=a[b[i]+1];
}
else{
break;
}
}
w=max(w,v);
}while(next_permutation(b,b+n));
cout<<w<<endl;
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPGFsZ29yaXRobT4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBuLG0sYVsxMDBdLHhbMTAwXVsxMDBdLHAscSxiWzEyXT17MCwxLDIsMyw0LDUsNiw3LDgsOSwxMCwxMX0sdix3OwoKaW50IG1haW4oKXsKCWNpbj4+bj4+bTsKCWZvcihpbnQgaT0xO2k8PW47aSsrKXsKCQljaW4+PmFbaV07Cgl9Cglmb3IoaW50IGk9MTtpPD1tO2krKyl7CgkJY2luPj5wPj5xOwoJCXhbcF1bcV09MTsKCQl4W3FdW3BdPTE7Cgl9Cglkb3sKCQl2PWFbYlswXSsxXTsKCQlmb3IoaW50IGk9MTtpPG47aSsrKXsKCQkJaWYoeFtiW2ktMV0rMV1bYltpXSsxXT09MSl7CgkJCQl2Kz1hW2JbaV0rMV07CgkJCX0KCQkJZWxzZXsKCQkJCWJyZWFrOwoJCQl9CgkJfQoJCXc9bWF4KHcsdik7Cgl9d2hpbGUobmV4dF9wZXJtdXRhdGlvbihiLGIrbikpOwoJY291dDw8dzw8ZW5kbDsKCXJldHVybiAwOwp9