#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define tcl(a,b,c) for(a=b;a<=c;a++)
const int maxx=20001;
struct data
{
int x,y,dis;
}a[100001];
int ti[maxx],f[maxx];
int getf(int x)
{
if(f[x]==x) return x;
else f[x]=getf(f[x]);
return f[x];
}
bool cmp(data a,data b)
{
return a.dis<b.dis;
}
int N,P,ans;
int main()
{
int i,r=0,mins=99999999;
cin>>N>>P;
tcl(i,1,N)
{
cin>>ti[i];
mins=min(ti[i],mins);
}
tcl(i,1,N)
{
f[i]=i;
}
tcl(i,1,P)
{
cin>>a[i].x>>a[i].y>>a[i].dis;
a[i].dis=a[i].dis*2+ti[a[i].x]+ti[a[i].y];//处理特殊的边权
}
sort(a+1,a+1+P,cmp);
for(i=1;r<N-1;i++)
{
int t1=getf(a[i].x);
int t2=getf(a[i].y);
if(t1!=t2)
{
ans+=a[i].dis;
f[t1]=t2;//这里错过
r++;
}
}
ans+=mins;//从最小节点开始
cout<<ans<<endl;
return 0;
}