#include <bits/stdc++.h>
#define maxn 10001
using namespace std;
int c[maxn];
int f[maxn];
struct node
{
int x;
int y;
int data;
int m;
node()
{
x = y = data = m = 0;
}
};
node a[maxn];
bool cmp(const node &a,const node &b)
{
return a.data < b.data;
}
int ifind(int x)
{
if(f[x] != x)
{
return f[x] = ifind(f[x]);
}
return f[x];
}
using namespace std;
int main()
{
int n,m;
scanf("%d %d",&n,&m);
int minn = 0x3f;
for(int i = 1;i <= n;i++)
{
cin >> c[i];
if(c[i] < minn)
{
minn = c[i];
}
}
for(int i = 1;i < maxn;i++)
{
f[i] = i;
}
for(int i = 1;i <= m;i++)
{
cin >> a[i].x >> a[i].y >> a[i].data;
}
sort(a + 1,a + 1 + m,cmp);
int ans = 0;
int t = 0;
int w[maxn];
for(int i = 1;i <= m;i++)
{
int r1 = ifind(a[i].x);
int r2 = ifind(a[i].y);
w[i] = 2 * a[i].data + c[a[i].x] + c[a[i].y];
if(r1 != r2)
{
f[r1] = r2;
ans += w[i];
t++;
}
if(t == n - 1)
{
break;
}
}
cout << ans + minn;
cout << endl;
return 0;
}