#include <bits/stdc++.h>
#define SPEED ios::sync_with_stdio(false); cin.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define ll unsigned long long
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define INF 1e18+100
#define eps 0.00001
#define stp setprecision(20)
#define endl '\n'
using namespace std;

  struct DSU
{
	int S;

	struct node
	{
		int p; ll sum;
	};
	vector<node> dsu;

	DSU(int n)
	{
		S = n;
		for(int i = 0; i < n; i++)
		{
			node tmp;
			tmp.p = i; tmp.sum = 0;
			dsu.pb(tmp);
		}
	}

	void reset(int n)
	{
		dsu.clear();
		S = n;
		for(int i = 0; i < n; i++)
		{
			node tmp;
			tmp.p = i; tmp.sum = 0;
			dsu.pb(tmp);
		}
	}

	int rt(int u)
	{
		if(dsu[u].p == u) return u;

		return dsu[u].p = rt(dsu[u].p);
	}

	void merge(int u, int v)
	{
		u = rt(u); v = rt(v);
		if(u == v) return ;

		dsu[v].p = u;
		dsu[u].sum += dsu[v].sum;
	}

	bool sameset(int u, int v)
	{
		if(rt(u) == rt(v)) return true;
		return false;
	}

	ll getstat(int u)
	{
		return dsu[rt(u)].sum;
	}
};

ll a[200010];
int main()
{    SPEED;

       int n,m;
       cin>>n>>m;ll b =INF; int id =0 ;
       loop(i,0,n)
        {cin>>a[i];;
           if(a[i]<b)id=i,b=a[i];
		}

       vector< pair<ll,pll> > edj;

         loop(i,0,m)
          {
          	 ll u,v,w;
          	  cin>>u>>v>>w;
          	  edj.pb({w,{u-1,v-1}});

		  }

		   //cout<<b<<endl;

					 loop(j,0,n)
					  {
					  	 if(j==id)continue;

					  	 edj.pb({a[id]+a[j],{j,id}});
						}

		 sort(edj.begin(),edj.end());

		 	 DSU dsu(n); ll ans=0;
		 loop(i,0,edj.size())
		  {
		          int u = edj[i].ss.ff;int v=edj[i].ss.ss;
		           if(dsu.rt(u)!=dsu.rt(v))
		            {
		            	  dsu.merge(u,v);
		            	  ans+= edj[i].ff;
					}
		  }
		  cout<<ans<<endl;
		 return 0;

}


#include <bits/stdc++.h>
#define SPEED ios::sync_with_stdio(false); cin.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define INF 1e18+100
#define eps 0.00001
#define stp setprecision(20)
#define endl '\n'
using namespace std;

  struct DSU
{
	int S;

	struct node
	{
		int p; ll sum;
	};
	vector<node> dsu;

	DSU(int n)
	{
		S = n;
		for(int i = 0; i < n; i++)
		{
			node tmp;
			tmp.p = i; tmp.sum = 0;
			dsu.pb(tmp);
		}
	}

	void reset(int n)
	{
		dsu.clear();
		S = n;
		for(int i = 0; i < n; i++)
		{
			node tmp;
			tmp.p = i; tmp.sum = 0;
			dsu.pb(tmp);
		}
	}

	int rt(int u)
	{
		if(dsu[u].p == u) return u;

		return dsu[u].p = rt(dsu[u].p);
	}

	void merge(int u, int v)
	{
		u = rt(u); v = rt(v);
		if(u == v) return ;
		if(rand()%2==0) swap(u, v);
		dsu[v].p = u;
		dsu[u].sum += dsu[v].sum;
	}

	bool sameset(int u, int v)
	{
		if(rt(u) == rt(v)) return true;
		return false;
	}

	ll getstat(int u)
	{
		return dsu[rt(u)].sum;
	}
};

ll a[200010];
int main()
{    SPEED;

       int n,m;
       cin>>n>>m;ll b =INF;
       loop(i,0,n)
        {cin>>a[i];b=min(b,a[i]);
		}

       vector< pair<ll,pll> > edj;

         loop(i,0,m)
          {
          	  int u,v,w;
          	  cin>>u>>v>>w;
          	  edj.pb({w,{u-1,v-1}});

		  }

		   //cout<<b<<endl;
		  loop(i,0,n)
		   {
		   	   if(a[i]==b)
		   	     {
		   	      int id = i;

					 loop(j,0,n)
					  {
					  	 if(j==id)continue;

					  	 edj.pb({a[id]+a[j],{j,id}});
						}

		   	       break;
					}
		   }

		 sort(edj.begin(),edj.end());

		 	 DSU dsu(n); ll ans=0;
		 loop(i,0,edj.size())
		  {
		          int u = edj[i].ss.ff;int v=edj[i].ss.ss;
		           if(dsu.rt(u)!=dsu.rt(v))
		            {
		            	  dsu.merge(u,v);
		            	  ans+= edj[i].ff;
					}
		  }
		  cout<<ans<<endl;
		 return 0;

}


#include <bits/stdc++.h>
#define SPEED ios::sync_with_stdio(false); cin.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define INF 1e18
#define eps 0.00001
#define stp setprecision(20)
#define endl '\n'
using namespace std;

  struct DSU
{
	int S;

	struct node
	{
		int p; ll sum;
	};
	vector<node> dsu;

	DSU(int n)
	{
		S = n;
		for(int i = 0; i < n; i++)
		{
			node tmp;
			tmp.p = i; tmp.sum = 0;
			dsu.pb(tmp);
		}
	}

	void reset(int n)
	{
		dsu.clear();
		S = n;
		for(int i = 0; i < n; i++)
		{
			node tmp;
			tmp.p = i; tmp.sum = 0;
			dsu.pb(tmp);
		}
	}

	int rt(int u)
	{
		if(dsu[u].p == u) return u;
		dsu[u].p = rt(dsu[u].p);
		return dsu[u].p;
	}

	void merge(int u, int v)
	{
		u = rt(u); v = rt(v);
		if(u == v) return ;
		if(rand()&1) swap(u, v);
		dsu[v].p = u;
	//	dsu[u].sum += dsu[v].sum;
	}

	bool sameset(int u, int v)
	{
		if(rt(u) == rt(v)) return true;
		return false;
	}

	ll getstat(int u)
	{
		return dsu[rt(u)].sum;
	}
};

ll a[200010];
int main()
{    SPEED;

       int n,m;
       cin>>n>>m;ll b =INT_MAX;
       loop(i,0,n)
        {cin>>a[i];b=min(b,a[i]);
		}

       vector< pair<ll,pll> > edj;

         loop(i,0,m)
          {
          	  int u,v,w;
          	  cin>>u>>v>>w;
          	  edj.pb({w,{u-1,v-1}});

		  }

		   //cout<<b<<endl;
		  loop(i,0,n)
		   {
		   	   if(a[i]==b)
		   	     {
		   	      int id = i;

					 loop(j,0,n)
					  {
					  	 if(j==id)continue;

					  	 edj.pb({a[id]+a[j],{id,j}});
						}

		   	       break;
					}
		   }

		 sort(edj.begin(),edj.end());

		 	 DSU dsu(n); ll ans=0;dsu.reset(n);
		 loop(i,0,edj.size())
		  {
		          int u = edj[i].ss.ff;int v=edj[i].ss.ss;
		           if(dsu.rt(u)!=dsu.rt(v))
		            {
		            	  dsu.merge(u,v);
		            	  ans+= edj[i].ff;
					}
		  }
		  cout<<ans<<endl;
		 return 0;

}


#include <bits/stdc++.h>
#define SPEED ios::sync_with_stdio(false); cin.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define INF 1e18+100
#define eps 0.00001
#define stp setprecision(20)
#define endl '\n'
using namespace std;

  struct DSU
{
	int S;

	struct node
	{
		int p; ll sum;
	};
	vector<node> dsu;

	DSU(int n)
	{
		S = n;
		for(int i = 0; i < n; i++)
		{
			node tmp;
			tmp.p = i; tmp.sum = 0;
			dsu.pb(tmp);
		}
	}

	void reset(int n)
	{
		dsu.clear();
		S = n;
		for(int i = 0; i < n; i++)
		{
			node tmp;
			tmp.p = i; tmp.sum = 0;
			dsu.pb(tmp);
		}
	}

	int rt(int u)
	{
		if(dsu[u].p == u) return u;

		return dsu[u].p = rt(dsu[u].p);
	}

	void merge(int u, int v)
	{
		u = rt(u); v = rt(v);
		if(u == v) return ;

		dsu[v].p = u;
		dsu[u].sum += dsu[v].sum;
	}

	bool sameset(int u, int v)
	{
		if(rt(u) == rt(v)) return true;
		return false;
	}

	ll getstat(int u)
	{
		return dsu[rt(u)].sum;
	}
};

ll a[200010];
int main()
{    SPEED;

       int n,m;
       cin>>n>>m;ll b =INF; int id =0 ;
       loop(i,0,n)
        {cin>>a[i];;
           if(a[i]<b)id=i,b=a[i];
		}

       vector< pair<ll,pll> > edj;

         loop(i,0,m)
          {
          	  int u,v,w;
          	  cin>>u>>v>>w;
          	  edj.pb({w,{u-1,v-1}});

		  }

		   //cout<<b<<endl;

					 loop(j,0,n)
					  {
					  	 if(j==id)continue;

					  	 edj.pb({a[id]+a[j],{j,id}});
						}

		 sort(edj.begin(),edj.end());

		 	 DSU dsu(n); ll ans=0;
		 loop(i,0,edj.size())
		  {
		          int u = edj[i].ss.ff;int v=edj[i].ss.ss;
		           if(dsu.rt(u)!=dsu.rt(v))
		            {
		            	  dsu.merge(u,v);
		            	  ans+= edj[i].ff;
					}
		  }
		  cout<<ans<<endl;
		 return 0;

}


#include <bits/stdc++.h>
#define SPEED ios::sync_with_stdio(false); cin.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define INF 1e18+100
#define eps 0.00001
#define stp setprecision(20)
#define endl '\n'
using namespace std;

  struct DSU
{
	int S;

	struct node
	{
		int p; ll sum;
	};
	vector<node> dsu;

	DSU(int n)
	{
		S = n;
		for(int i = 0; i < n; i++)
		{
			node tmp;
			tmp.p = i; tmp.sum = 0;
			dsu.pb(tmp);
		}
	}

	void reset(int n)
	{
		dsu.clear();
		S = n;
		for(int i = 0; i < n; i++)
		{
			node tmp;
			tmp.p = i; tmp.sum = 0;
			dsu.pb(tmp);
		}
	}

	int rt(int u)
	{
		if(dsu[u].p == u) return u;

		return dsu[u].p = rt(dsu[u].p);
	}

	void merge(int u, int v)
	{
		u = rt(u); v = rt(v);
		if(u == v) return ;

		dsu[v].p = u;
		dsu[u].sum += dsu[v].sum;
	}

	bool sameset(int u, int v)
	{
		if(rt(u) == rt(v)) return true;
		return false;
	}

	ll getstat(int u)
	{
		return dsu[rt(u)].sum;
	}
};

ll a[200010];
int main()
{    SPEED;

       int n,m;
       cin>>n>>m;ll b =INF;
       loop(i,0,n)
        {cin>>a[i];b=min(b,a[i]);
		}

       vector< pair<ll,pll> > edj;

         loop(i,0,m)
          {
          	  int u,v,w;
          	  cin>>u>>v>>w;
          	  edj.pb({w,{u-1,v-1}});

		  }

		   //cout<<b<<endl;
		  loop(i,0,n)
		   {
		   	   if(a[i]==b)
		   	     {
		   	      int id = i;

					 loop(j,0,n)
					  {
					  	 if(j==id)continue;

					  	 edj.pb({a[id]+a[j],{j,id}});
						}

		   	       break;
					}
		   }

		 sort(edj.begin(),edj.end());

		 	 DSU dsu(n); ll ans=0;
		 loop(i,0,edj.size())
		  {
		          int u = edj[i].ss.ff;int v=edj[i].ss.ss;
		           if(dsu.rt(u)!=dsu.rt(v))
		            {
		            	  dsu.merge(u,v);
		            	  ans+= edj[i].ff;
					}
		  }
		  cout<<ans<<endl;
		 return 0;

}


#include <bits/stdc++.h>
#define SPEED ios::sync_with_stdio(false); cin.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define ll usigned long long
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define INF 1e18+100
#define eps 0.00001
#define stp setprecision(20)
#define endl '\n'
using namespace std;

  struct DSU
{
	int S;

	struct node
	{
		int p; ll sum;
	};
	vector<node> dsu;

	DSU(int n)
	{
		S = n;
		for(int i = 0; i < n; i++)
		{
			node tmp;
			tmp.p = i; tmp.sum = 0;
			dsu.pb(tmp);
		}
	}

	void reset(int n)
	{
		dsu.clear();
		S = n;
		for(int i = 0; i < n; i++)
		{
			node tmp;
			tmp.p = i; tmp.sum = 0;
			dsu.pb(tmp);
		}
	}

	int rt(int u)
	{
		if(dsu[u].p == u) return u;

		return dsu[u].p = rt(dsu[u].p);
	}

	void merge(int u, int v)
	{
		u = rt(u); v = rt(v);
		if(u == v) return ;

		dsu[v].p = u;
		dsu[u].sum += dsu[v].sum;
	}

	bool sameset(int u, int v)
	{
		if(rt(u) == rt(v)) return true;
		return false;
	}

	ll getstat(int u)
	{
		return dsu[rt(u)].sum;
	}
};

ll a[200010];
int main()
{    SPEED;

       int n,m;
       cin>>n>>m;ll b =INF; int id =0 ;
       loop(i,0,n)
        {cin>>a[i];;
           if(a[i]<b)id=i,b=a[i];
		}

       vector< pair<ll,pll> > edj;

         loop(i,0,m)
          {
          	  int u,v,w;
          	  cin>>u>>v>>w;
          	  edj.pb({w,{u-1,v-1}});

		  }

		   //cout<<b<<endl;

					 loop(j,0,n)
					  {
					  	 if(j==id)continue;

					  	 edj.pb({a[id]+a[j],{j,id}});
						}

		 sort(edj.begin(),edj.end());

		 	 DSU dsu(n); ll ans=0;
		 loop(i,0,edj.size())
		  {
		          int u = edj[i].ss.ff;int v=edj[i].ss.ss;
		           if(dsu.rt(u)!=dsu.rt(v))
		            {
		            	  dsu.merge(u,v);
		            	  ans+= edj[i].ff;
					}
		  }
		  cout<<ans<<endl;
		 return 0;

}


#include <bits/stdc++.h>
#define SPEED ios::sync_with_stdio(false); cin.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define ll  long long
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define INF 1e18+100
#define eps 0.00001
#define stp setprecision(20)
#define endl '\n'
using namespace std;

  ll parent[200003];
ll _rank[200003];

void mi(ll v){
    parent[v]=v;
    _rank[v]=0;
}

ll f(ll v){
    if(v==parent[v]){
        return v;
    }
    return parent[v]=f(parent[v]);
}

void un(ll a, ll b){
    a=f(a);
    b=f(b);
    if(a!=b){
        if(_rank[a]<_rank[b]){
            swap(a, b);
        }
        parent[b]=a;
        if(_rank[a]==_rank[b]){
            _rank[a]++;
        }
    }
}

ll a[200010];
int main()
{    SPEED;

       int n,m;
       cin>>n>>m;ll b =INF; int id =0 ;
       loop(i,0,n)
        {cin>>a[i];;
           if(a[i]<b)id=i,b=a[i];
		}

       vector< pair<ll,pii> > edj;

         loop(i,0,m)
          {
          	  int u,v,w;
          	  cin>>u>>v>>w;
          	  edj.pb({w,{u-1,v-1}});

		  }

		   //cout<<b<<endl;

					 loop(j,0,n)
					  {
					  	 if(j==id)continue;

					  	 edj.pb({a[id]+a[j],{j,id}});
						}

		 sort(edj.begin(),edj.end());
		 loop(i,0,n){
                    mi(i);
    }
		  unsigned ll ans=0;
		 loop(i,0,edj.size())
		  {
		          int u = edj[i].ss.ff;int v=edj[i].ss.ss;
		           if(f(u)!=f(v))
		            {

		            	  ans+= edj[i].ff;
		            	  un(u,v);
					}
		  }
		  cout<<ans<<endl;

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int>  P;
vector<vector<ll> >v;
const int maxn = 2e6;
ll ans[maxn];
ll val[maxn];
ll n,m;
struct node1 {
    ll u,v,w;
} gg[maxn];

struct node {
    ll id, val;
} g[maxn];
int cnt = 0;

bool cmp1(struct node a,struct node b) {
    return a.val < b.val;
}
int fa[maxn];
int Find(int x) {
    if(x == fa[x]) return x;
    return Find(fa[x]);
}
bool cmp2(struct node1 a,struct node1 b) {
    return a.w < b.w;
}
ll krus() {
    ll ans = 0;
//    cout << cnt << endl;
    for(int i = 1; i < cnt; i++) {
        int u = gg[i].u;
        int v = gg[i].v;
        int U = Find(u);
        int V = Find(v);
        if(U != V) {
//        cout << U << "   " << V << endl;
            fa[U] = V;
            ans += gg[i].w;
        }
    }
    return ans;
}
int main() {
    while(~scanf("%lld%lld",&n,&m)){
        for(int i = 1; i <= 4e5 + 2500; i++)
            fa[i] = i;
        cnt = 1;
        for(int i = 1; i <= n; i++){
            scanf("%lld",&g[i].val);g[i].id = i;
        }
        sort(g + 1,g + 1 + n,cmp1);
        ll id1 = g[1].id;
//        cout << id1 <<endl;
        for(int i = 2; i <= n; i++) {
            gg[cnt].u = g[1].id;
            gg[cnt].v = g[i].id;
            gg[cnt++].w = g[1].val + g[i].val;
//            id1 = g[i].id;
            if(i == 7 ){
//                cout << gg[cnt - 1].u << "    asdasda   " << gg[cnt - 1].v << "    " <<gg[cnt].w << endl;
            }
        }
        for(int i = 1; i <= m; i++) {
            ll u,v,w;
            scanf("%lld%lld%lld",&u,&v,&w);

//            cin >> u >> v >> w;
            gg[cnt].u = u;
            gg[cnt].v = v;
            gg[cnt++].w = w;
        }
        sort(gg + 1,gg + cnt,cmp2);
        printf("%lld\n",krus());
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int>  P;
vector<vector<ll> >v;
const int maxn = 2e6;
ll ans[maxn];
ll val[maxn];
ll n,m;
struct node1 {
    ll u,v,w;
} gg[maxn];

struct node {
    ll id, val;
} g[maxn];
int cnt = 0;

bool cmp1(struct node a,struct node b) {
    return a.val < b.val;
}
int fa[maxn];
int Find(int x) {
    if(x == fa[x]) return x;
    return Find(fa[x]);
}
bool cmp2(struct node1 a,struct node1 b) {
    return a.w < b.w;
}
int krus() {
    ll ans = 0;
//    cout << cnt << endl;
    for(int i = 1; i < cnt; i++) {
        int u = gg[i].u;
        int v = gg[i].v;
        int U = Find(u);
        int V = Find(v);
        if(U != V) {
//        cout << U << "   " << V << endl;
            fa[U] = V;
            ans += gg[i].w;
        }
    }
    return ans;
}
int main() {
    while(cin >> n >> m ) {
        for(int i = 1; i <= 4e5 + 2500; i++)
            fa[i] = i;
        cnt = 1;
        for(int i = 1; i <= n; i++) cin >> g[i].val,g[i].id = i;
        sort(g + 1,g + 1 + n,cmp1);
        ll id1 = g[1].id;
//        cout << id1 <<endl;
        for(int i = 2; i <= n; i++) {
            gg[cnt].u = id1;
            gg[cnt].v = i;
            gg[cnt++].w = g[1].val + g[i].val;
            id1 = g[i].id;
        }
        for(int i = 1; i <= m; i++) {
            ll u,v,w;
            cin >> u >> v >> w;
            gg[cnt].u = u;
            gg[cnt].v = v;
            gg[cnt++].w = w;
        }
        sort(gg + 1,gg + cnt,cmp2);
        for(int i = 1; i < cnt; i++) {
//            cout <<gg[i].v << "   " <<gg[i].u << "   " <<gg[i].w <<endl;
        }
        cout << krus() << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int>  P;
vector<vector<ll> >v;
const int maxn = 2e6;
ll ans[maxn];
ll val[maxn];
ll n,m;
struct node1 {
    ll u,v,w;
} gg[maxn];

struct node {
    ll id, val;
} g[maxn];
int cnt = 0;

bool cmp1(struct node a,struct node b) {
    return a.val < b.val;
}
int fa[maxn];
int Find(int x) {
    if(x == fa[x]) return x;
    return Find(fa[x]);
}
bool cmp2(struct node1 a,struct node1 b) {
    return a.w < b.w;
}
int krus() {
    ll ans = 0;
//    cout << cnt << endl;
    for(int i = 1; i < cnt; i++) {
        int u = gg[i].u;
        int v = gg[i].v;
        int U = Find(u);
        int V = Find(v);
        if(U != V) {
//        cout << U << "   " << V << endl;
            fa[U] = V;
            ans += gg[i].w;
        }
    }
    return ans;
}
int main() {
    while(cin >> n >> m ) {
        for(int i = 1; i <= 4e5 + 2500; i++)
            fa[i] = i;
        cnt = 1;
        for(int i = 1; i <= n; i++) cin >> g[i].val,g[i].id = i;
        sort(g + 1,g + 1 + n,cmp1);
        ll id1 = g[1].id;
//        cout << id1 <<endl;
        for(int i = 2; i <= n; i++) {
            gg[cnt].u = g[1].id;
            gg[cnt].v = g[i].id;
            gg[cnt++].w = g[1].val + g[i].val;
//            id1 = g[i].id;
            if(i == 7 ){
//                cout << gg[cnt - 1].u << "    asdasda   " << gg[cnt - 1].v << "    " <<gg[cnt].w << endl;
            }
        }
        for(int i = 1; i <= m; i++) {
            ll u,v,w;
            cin >> u >> v >> w;
            gg[cnt].u = u;
            gg[cnt].v = v;
            gg[cnt++].w = w;
        }
        sort(gg + 1,gg + cnt,cmp2);
        for(int i = 1; i < cnt; i++) {
//            cout <<gg[i].v << "   " <<gg[i].u << "   " <<gg[i].w <<endl;
        }
        cout << krus() << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int>  P;
vector<vector<ll> >v;
const int maxn = 2e6;
ll ans[maxn];
ll val[maxn];
int id[maxn];
ll n,m;
struct node1 {
    ll u,v,w;
} gg[maxn];

struct node {
    ll id, val;
} g[maxn];
int cnt = 0;

bool cmp1(struct node a,struct node b) {
    return a.val < b.val;
}
int fa[maxn];
int Find(int x) {
    if(x == fa[x]) return x;
    return Find(fa[x]);
}
bool cmp2(struct node1 a,struct node1 b) {
    return a.w < b.w;
}
ll krus() {
    ll ans = 0;
    ll num = 0;
//    cout << cnt << endl;
    for(int i = 1; i < cnt + 1; i++) {
        int u = gg[i].u;
        int v = gg[i].v;
        int U = Find(u);
        int V = Find(v);
        if(U != V) {
            fa[U] = V;
            num++;
            ans += gg[i].w;
        }
        if(num == n - 1) break;
    }
    return ans;
}
int main() {
    while(~scanf("%lld%lld",&n,&m)) {
        for(int i = 1; i <= n; i++)
            fa[i] = i;
        cnt = 1;
        for(int i = 1; i <= n; i++) {
            scanf("%lld",&g[i].val);
            g[i].id = i;
        }
        sort(g + 1,g + 1 + n,cmp1);
        for(int i = 2; i <= n; i++) {
            gg[cnt].u = g[1].id;
            gg[cnt].v = g[i].id;
            gg[cnt++].w = g[1].val + g[i].val;
        }

        for(int i = 1; i <= m; i++) {
            ll u,v,w;
            scanf("%lld%lld%lld",&u,&v,&w);
            gg[cnt].u = u;
            gg[cnt].v = v;
            gg[cnt++].w = w;
        }
        sort(gg + 1,gg + cnt + 1,cmp2);
        printf("%lld\n",krus());
    }
    return 0;
}


    #include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int>  P;
vector<vector<ll> >v;
const int maxn = 2e5 + 500;
ll ans[maxn];
ll val[maxn];
int id[maxn];
ll n,m;
struct node1 {
    ll u,v,w;
} gg[maxn];

struct node {
    ll id, val;
} g[maxn];
int cnt = 0;

bool cmp1(struct node a,struct node b) {
    return a.val < b.val;
}
int fa[maxn];
int Find(int x) {
    if(x == fa[x]) return x;
    return Find(fa[x]);
}
bool cmp2(struct node1 a,struct node1 b) {
    return a.w < b.w;
}
ll krus() {
    ll ans = 0;
    ll num = 0;
//    cout << cnt << endl;
    for(int i = 1; i < cnt + 1; i++) {
        int u = gg[i].u;
        int v = gg[i].v;
        int U = Find(u);
        int V = Find(v);
        if(U != V) {
            fa[U] = V;
            num++;
            ans += gg[i].w;
        }
        if(num == n - 1) break;
    }
    return ans;
}
int main() {
    while(~scanf("%lld%lld",&n,&m)) {
        for(int i = 1; i <= n; i++)
            fa[i] = i;
        cnt = 1;
        for(int i = 1; i <= n; i++) {
            scanf("%lld",&g[i].val);
            g[i].id = i;
        }
        sort(g + 1,g + 1 + n,cmp1);
        for(int i = 2; i <= n; i++) {
            gg[cnt].u = g[1].id;
            gg[cnt].v = g[i].id;
            gg[cnt++].w = g[1].val + g[i].val;
        }

        for(int i = 1; i <= m; i++) {
            ll u,v,w;
            scanf("%lld%lld%lld",&u,&v,&w);
            gg[cnt].u = u;
            gg[cnt].v = v;
            gg[cnt++].w = w;
        }
        sort(gg + 1,gg + cnt + 1,cmp2);
        printf("%lld\n",krus());
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int>  P;
vector<vector<ll> >v;
const int maxn = 2e6;
ll ans[maxn];
ll val[maxn];
int id[maxn];
ll n,m;
struct node1 {
    ll u,v,w;
} gg[maxn];

struct node {
    ll id, val;
} g[maxn];
int cnt = 0;

bool cmp1(struct node a,struct node b) {
    return a.val < b.val;
}
int fa[maxn];
int Find(int x) {
    if(x == fa[x]) return x;
    return Find(fa[x]);
}
bool cmp2(struct node1 a,struct node1 b) {
    return a.w < b.w;
}
ll krus() {
    ll ans = 0;
    ll num = 0;
//    cout << cnt << endl;
    for(int i = 1; i < cnt + 1; i++) {
        int u = gg[i].u;
        int v = gg[i].v;
        int U = Find(u);
        int V = Find(v);
        if(U != V) {
            fa[U] = V;
            num++;
            ans += gg[i].w;
        }
        if(num == n - 1) break;
    }
    return ans;
}
int main() {
    while(~scanf("%lld%lld",&n,&m)){
        for(int i = 1; i < 1e6; i++)
            fa[i] = i;
        cnt = 1;
        for(int i = 1; i <= n; i++){
            scanf("%lld",&g[i].val);g[i].id = i;
        }
        sort(g + 1,g + 1 + n,cmp1);
//        cout << id1 <<endl;
        for(int i = 2; i <= n; i++) {
            gg[cnt].u = g[1].id;
            gg[cnt].v = g[i].id;
            gg[cnt++].w = g[1].val + g[i].val;
//            id1 = g[i].id;
            if(i == 7 ){
//                cout << gg[cnt - 1].u << "    asdasda   " << gg[cnt - 1].v << "    " <<gg[cnt].w << endl;
            }
        }
//        for(int i = 1;i <= )
        for(int i = 1; i <= m; i++) {
            ll u,v,w;
            scanf("%lld%lld%lld",&u,&v,&w);

//            cin >> u >> v >> w;
            gg[cnt].u = u;
            gg[cnt].v = v;
            gg[cnt++].w = w;
        }
        sort(gg + 1,gg + cnt + 1,cmp2);
        printf("%lld\n",krus());
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int>  P;
vector<vector<ll> >v;
const int maxn = 2e6;
ll ans[maxn];
ll val[maxn];
int id[maxn];
ll n,m;
struct node1 {
    ll u,v,w;
} gg[maxn];

struct node {
    ll id, val;
} g[maxn];
int cnt = 0;

bool cmp1(struct node a,struct node b) {
    return a.val < b.val;
}
int fa[maxn];
int Find(int x) {
    if(x == fa[x]) return x;
    return Find(fa[x]);
}
bool cmp2(struct node1 a,struct node1 b) {
    return a.w < b.w;
}
ll krus() {
    ll ans = 0;
    ll num = 0;
//    cout << cnt << endl;
    for(int i = 1; i < cnt + 1; i++) {
        int u = gg[i].u;
        int v = gg[i].v;
        int U = Find(u);
        int V = Find(v);
        if(U != V) {
            fa[U] = V;
            num++;
            ans += gg[i].w;
        }
        if(num == n - 1) break;
    }
    return ans;
}
int main() {
    while(~scanf("%lld%lld",&n,&m)) {
        for(int i = 1; i < 4e5; i++)
            fa[i] = i;
        cnt = 1;
        for(int i = 1; i <= n; i++) {
            scanf("%lld",&g[i].val);
            g[i].id = i;
        }
        sort(g + 1,g + 1 + n,cmp1);
        for(int i = 2; i <= n; i++) {
            gg[cnt].u = g[1].id;
            gg[cnt].v = g[i].id;
            gg[cnt++].w = g[1].val + g[i].val;
        }

        for(int i = 1; i <= m; i++) {
            ll u,v,w;
            scanf("%lld%lld%lld",&u,&v,&w);
            gg[cnt].u = u;
            gg[cnt].v = v;
            gg[cnt++].w = w;
        }
        sort(gg + 1,gg + cnt + 1,cmp2);
        printf("%lld\n",krus());
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int>  P;
vector<vector<ll> >v;
const int maxn = 2e6;
ll ans[maxn];
ll val[maxn];
ll n,m;
struct node1 {
    ll u,v,w;
} gg[maxn];

struct node {
    ll id, val;
} g[maxn];
int cnt = 0;

bool cmp1(struct node a,struct node b) {
    return a.val < b.val;
}
int fa[maxn];
int Find(int x) {
    if(x == fa[x]) return x;
    return Find(fa[x]);
}
bool cmp2(struct node1 a,struct node1 b) {
    return a.w < b.w;
}
int krus() {
    ll ans = 0;
//    cout << cnt << endl;
    for(int i = 1; i < cnt; i++) {
        int u = gg[i].u;
        int v = gg[i].v;
        int U = Find(u);
        int V = Find(v);
        if(U != V) {
//        cout << U << "   " << V << endl;
            fa[U] = V;
            ans += gg[i].w;
        }
    }
    return ans;
}
int main() {
    while(cin >> n >> m ) {
        for(int i = 1; i <= 4e5 + 2500; i++)
            fa[i] = i;
        cnt = 1;
        for(int i = 1; i <= n; i++) cin >> g[i].val,g[i].id = i;
        sort(g + 1,g + 1 + n,cmp1);
        ll id1 = g[1].id;
//        cout << id1 <<endl;
        for(int i = 2; i <= n; i++) {
            gg[cnt].u = 1;
            gg[cnt].v = i;
            gg[cnt++].w = g[1].val + g[i].val;
            id1 = g[i].id;
        }
        for(int i = 1; i <= m; i++) {
            ll u,v,w;
            cin >> u >> v >> w;
            gg[cnt].u = u;
            gg[cnt].v = v;
            gg[cnt++].w = w;
        }
        sort(gg + 1,gg + cnt,cmp2);
        for(int i = 1; i < cnt; i++) {
//            cout <<gg[i].v << "   " <<gg[i].u << "   " <<gg[i].w <<endl;
        }
        cout << krus() << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int>  P;
vector<vector<ll> >v;
const int maxn = 1e6 + 500;
int id[maxn];
ll n,m;
struct node1 {
    ll u,v,w;
} gg[maxn];

struct node {
    ll id, val;
} g[maxn];
int cnt = 0;

bool cmp1(struct node a,struct node b) {
    return a.val < b.val;
}
int fa[maxn];
int Find(int x) {
    if(x == fa[x]) return x;
    return Find(fa[x]);
}
bool cmp2(struct node1 a,struct node1 b) {
    return a.w < b.w;
}
ll krus() {
    ll ans = 0;
    ll num = 0;
//    cout << cnt << endl;
    for(int i = 1; i < cnt + 1; i++) {
        int u = gg[i].u;
        int v = gg[i].v;
        int U = Find(u);
        int V = Find(v);
        if(U != V) {
            fa[V] = U;
            num++;
            ans += gg[i].w; }
        if(num == n - 1) break;
    }
    return ans;
}
int main() {
    while(~scanf("%lld%lld",&n,&m)) {
        for(int i = 1; i <= n; i++)
            fa[i] = i;
        cnt = 1;
        for(int i = 1; i <= n; i++) {
            scanf("%lld",&g[i].val);
            g[i].id = i;
        }
        sort(g + 1,g + 1 + n,cmp1);
        for(int i = 2; i <= n; i++) {
            gg[cnt].u = g[1].id;
            gg[cnt].v = g[i].id;
            gg[cnt++].w = g[1].val + g[i].val;
        }

        for(int i = 1; i <= m; i++) {
            ll u,v,w;
            scanf("%lld%lld%lld",&u,&v,&w);
            gg[cnt].u = u;
            gg[cnt].v = v;
            gg[cnt++].w = w;
        }
        sort(gg + 1,gg + cnt + 1,cmp2);
        printf("%lld\n",krus());
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int>  P;
vector<vector<ll> >v;
const int maxn = 1e6 + 500;
ll n,m;
struct node1 {
    ll u,v,w;
} gg[maxn];
struct node {
    ll id, val;
} g[maxn];
int cnt = 0;

bool cmp1(struct node a,struct node b) {
    return a.val < b.val;
}
int fa[maxn];
int Find(int x) {
    if(x == fa[x]) return fa[x];
    return fa[x] = Find(fa[x]);
}
bool cmp2(struct node1 a,struct node1 b) {
    return a.w < b.w;
}
ll krus() {
    ll ans = 0;
    ll num = 0;
//    cout << cnt << endl;
    for(int i = 1; i < cnt + 1; i++) {
        int u = gg[i].u;
        int v = gg[i].v;
        int U = Find(u);
        int V = Find(v);
        if(U != V) {
            fa[V] = U;
            num++;
            ans += gg[i].w;
        }
        if(num == n - 1) break;
    }
    return ans;
}
int main() {
    while(~scanf("%lld%lld",&n,&m)) {
        for(int i = 0; i <= n + 20; i++)
            fa[i] = i;
        cnt = 1;
        for(int i = 1; i <= n; i++) {
            scanf("%lld",&g[i].val);
            g[i].id = i;
        }
        sort(g + 1,g + 1 + n,cmp1);
        for(int i = 2; i <= n; i++) {
            gg[cnt].u = g[1].id;
            gg[cnt].v = g[i].id;
            gg[cnt++].w = g[1].val + g[i].val;
        }
        for(int i = 1; i <= m; i++) {
            ll u,v,w;
            scanf("%lld%lld%lld",&u,&v,&w);
            gg[cnt].u = u;
            gg[cnt].v = v;
            gg[cnt++].w = w;
        }
        sort(gg + 1,gg + cnt + 1,cmp2);
        printf("%lld\n",krus());
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int>  P;
vector<vector<ll> >v;
const int maxn = 2e6;
ll ans[maxn];
ll val[maxn];
ll n,m;
struct node1 {
    ll u,v,w;
} gg[maxn];

struct node {
    ll id, val;
} g[maxn];
int cnt = 0;

bool cmp1(struct node a,struct node b) {
    return a.val < b.val;
}
int fa[maxn];
int Find(int x) {
    if(x == fa[x]) return x;
    return Find(fa[x]);
}
bool cmp2(struct node1 a,struct node1 b) {
    return a.w < b.w;
}
int krus() {
    ll ans = 0;
//    cout << cnt << endl;
    for(int i = 1; i < cnt; i++) {
        int u = gg[i].u;
        int v = gg[i].v;
        int U = Find(u);
        int V = Find(v);
        if(U != V) {
//        cout << U << "   " << V << endl;
            fa[U] = V;
            ans += gg[i].w;
        }
    }
    return ans;
}
int main() {
    while(cin >> n >> m ) {
        for(int i = 1; i <= 4e5 + 2500; i++)
            fa[i] = i;
        cnt = 1;
        for(int i = 1; i <= n; i++) cin >> g[i].val,g[i].id = i;
        sort(g + 1,g + 1 + n,cmp1);
        ll id1 = g[1].id;
//        cout << id1 <<endl;
        for(int i = 2; i <= n; i++) {
            gg[cnt].u = 1;
            gg[cnt].v = g[i].id;
            gg[cnt++].w = g[1].val + g[i].val;
            id1 = g[i].id;
            if(i == 7 ){
//                cout << gg[cnt - 1].u << "    asdasda   " << gg[cnt - 1].v << "    " <<gg[cnt].w << endl;
            }
        }
        for(int i = 1; i <= m; i++) {
            ll u,v,w;
            cin >> u >> v >> w;
            gg[cnt].u = u;
            gg[cnt].v = v;
            gg[cnt++].w = w;
        }
        sort(gg + 1,gg + cnt,cmp2);
        for(int i = 1; i < cnt; i++) {
//            cout <<gg[i].v << "   " <<gg[i].u << "   " <<gg[i].w <<endl;
        }
        cout << krus() << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int>  P;
vector<vector<ll> >v;
const int maxn = 2e5 + 500;
int id[maxn];
ll n,m;
struct node1 {
    ll u,v,w;
} gg[maxn];

struct node {
    ll id, val;
} g[maxn];
int cnt = 0;

bool cmp1(struct node a,struct node b) {
    return a.val < b.val;
}
int fa[maxn];
int Find(int x) {
    if(x == fa[x]) return x;
    return Find(fa[x]);
}
bool cmp2(struct node1 a,struct node1 b) {
    return a.w < b.w;
}
ll krus() {
    ll ans = 0;
    ll num = 0;
//    cout << cnt << endl;
    for(int i = 1; i < cnt + 1; i++) {
        int u = gg[i].u;
        int v = gg[i].v;
        int U = Find(u);
        int V = Find(v);
        if(U != V) {
            fa[V] = U;
            num++;
            ans += gg[i].w; }
        if(num == n - 1) break;
    }
    return ans;
}
int main() {
    while(~scanf("%lld%lld",&n,&m)) {
        for(int i = 1; i <= n; i++)
            fa[i] = i;
        cnt = 1;
        for(int i = 1; i <= n; i++) {
            scanf("%lld",&g[i].val);
            g[i].id = i;
        }
        sort(g + 1,g + 1 + n,cmp1);
        for(int i = 2; i <= n; i++) {
            gg[cnt].u = g[1].id;
            gg[cnt].v = g[i].id;
            gg[cnt++].w = g[1].val + g[i].val;
        }

        for(int i = 1; i <= m; i++) {
            ll u,v,w;
            scanf("%lld%lld%lld",&u,&v,&w);
            gg[cnt].u = u;
            gg[cnt].v = v;
            gg[cnt++].w = w;
        }
        sort(gg + 1,gg + cnt + 1,cmp2);
        printf("%lld\n",krus());
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int>  P;
vector<vector<ll> >v;
const int maxn = 2e6;
ll ans[maxn];
ll val[maxn];
ll n,m;
struct node1 {
    ll u,v,w;
} gg[maxn];

struct node {
    ll id, val;
} g[maxn];
int cnt = 0;

bool cmp1(struct node a,struct node b) {
    return a.val < b.val;
}
int fa[maxn];
int Find(int x) {
    if(x == fa[x]) return x;
    return Find(fa[x]);
}
bool cmp2(struct node1 a,struct node1 b) {
    return a.w < b.w;
}
int krus() {
    ll ans = 0;
//    cout << cnt << endl;
    for(int i = 1; i < cnt; i++) {
        int u = gg[i].u;
        int v = gg[i].v;
        int U = Find(u);
        int V = Find(v);
        if(U != V) {
//        cout << U << "   " << V << endl;
            fa[U] = V;
            ans += gg[i].w;
        }
    }
    return ans;
}
int main() {
    ios::sync_with_stdio(false);
    while(cin >> n >> m ) {
        for(int i = 1; i <= 4e5 + 2500; i++)
            fa[i] = i;
        cnt = 1;
        for(int i = 1; i <= n; i++) cin >> g[i].val,g[i].id = i;
        sort(g + 1,g + 1 + n,cmp1);
        ll id1 = g[1].id;
//        cout << id1 <<endl;
        for(int i = 2; i <= n; i++) {
            gg[cnt].u = g[1].id;
            gg[cnt].v = g[i].id;
            gg[cnt++].w = g[1].val + g[i].val;
//            id1 = g[i].id;
            if(i == 7 ){
//                cout << gg[cnt - 1].u << "    asdasda   " << gg[cnt - 1].v << "    " <<gg[cnt].w << endl;
            }
        }
        for(int i = 1; i <= m; i++) {
            ll u,v,w;
            cin >> u >> v >> w;
            gg[cnt].u = u;
            gg[cnt].v = v;
            gg[cnt++].w = w;
        }
        sort(gg + 1,gg + cnt,cmp2);
        cout << krus() << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int>  P;
vector<vector<ll> >v;
const int maxn = 1e6 + 500;
int id[maxn];
ll n,m;
struct node1 {
    ll u,v,w;
} gg[maxn];

struct node {
    ll id, val;
} g[maxn];
int cnt = 0;

bool cmp1(struct node a,struct node b) {
    return a.val < b.val;
}
int fa[maxn];
int Find(int x) {
    if(x == fa[x]) return x;
    return Find(fa[x]);
}
bool cmp2(struct node1 a,struct node1 b) {
    return a.w < b.w;
}
ll krus() {
    ll ans = 0;
    ll num = 0;
//    cout << cnt << endl;
    for(int i = 1; i < cnt + 1; i++) {
        int u = gg[i].u;
        int v = gg[i].v;
        int U = Find(u);
        int V = Find(v);
        if(U != V) {
            fa[V] = U;
            num++;
            ans += gg[i].w;
        }
        if(num == n - 1) break;
    }
    return ans;
}
int main() {
    while(~scanf("%lld%lld",&n,&m)) {
        for(int i = 0; i <= n + 20; i++)
            fa[i] = i;
        cnt = 1;
        for(int i = 1; i <= n; i++) {
            scanf("%lld",&g[i].val);
            g[i].id = i;
        }
        sort(g + 1,g + 1 + n,cmp1);
        for(int i = 2; i <= n; i++) {
            gg[cnt].u = g[1].id;
            gg[cnt].v = g[i].id;
            gg[cnt++].w = g[1].val + g[i].val;
        }
        for(int i = 1; i <= m; i++) {
            ll u,v,w;
            scanf("%lld%lld%lld",&u,&v,&w);
            gg[cnt].u = u;
            gg[cnt].v = v;
            gg[cnt++].w = w;
        }
        sort(gg + 1,gg + cnt + 1,cmp2);
        printf("%lld\n",krus());
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int>  P;
vector<vector<ll> >v;
const int maxn = 1e6 + 500;
ll n,m;
struct node1 {
    ll u,v,w;
} gg[maxn];
struct node {
    ll id, val;
} g[maxn];
int cnt = 0;

bool cmp1(struct node a,struct node b) {
    return a.val < b.val;
}
int fa[maxn];
int Find(int x) {
    if(x == fa[x]) return fa[x];
    return Find(fa[x]);
}
bool cmp2(struct node1 a,struct node1 b) {
    return a.w < b.w;
}
ll krus() {
    ll ans = 0;
    ll num = 0;
//    cout << cnt << endl;
    for(int i = 1; i < cnt + 1; i++) {
        int u = gg[i].u;
        int v = gg[i].v;
        int U = Find(u);
        int V = Find(v);
        if(U != V) {
            fa[V] = U;
            num++;
            ans += gg[i].w;
        }
        if(num == n - 1) break;
    }
    return ans;
}
int main() {
    while(~scanf("%lld%lld",&n,&m)) {
        for(int i = 0; i <= n + 20; i++)
            fa[i] = i;
        cnt = 1;
        for(int i = 1; i <= n; i++) {
            scanf("%lld",&g[i].val);
            g[i].id = i;
        }
        sort(g + 1,g + 1 + n,cmp1);
        for(int i = 2; i <= n; i++) {
            gg[cnt].u = g[1].id;
            gg[cnt].v = g[i].id;
            gg[cnt++].w = g[1].val + g[i].val;
        }
        for(int i = 1; i <= m; i++) {
            ll u,v,w;
            scanf("%lld%lld%lld",&u,&v,&w);
            gg[cnt].u = u;
            gg[cnt].v = v;
            gg[cnt++].w = w;
        }
        sort(gg + 1,gg + cnt + 1,cmp2);
        printf("%lld\n",krus());
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int>  P;
vector<vector<ll> >v;
const int maxn = 2e6;
ll ans[maxn];
ll val[maxn];
ll n,m;
struct node1 {
    ll u,v,w;
} gg[maxn];

struct node {
    ll id, val;
} g[maxn];
int cnt = 0;

bool cmp1(struct node a,struct node b) {
    return a.val < b.val;
}
int fa[maxn];
int Find(int x) {
    if(x == fa[x]) return x;
    return Find(fa[x]);
}
bool cmp2(struct node1 a,struct node1 b) {
    return a.w < b.w;
}
ll krus() {
    ll ans = 0;
    int num = 0;
//    cout << cnt << endl;
    for(int i = 1; i < cnt; i++) {
        int u = gg[i].u;
        int v = gg[i].v;
        int U = Find(u);
        int V = Find(v);
        if(U != V) {
//        cout << U << "   " << V << endl;
            fa[U] = V;
            num++;
            ans += gg[i].w;
        }
        if(num == n - 1) break;
    }
    return ans;
}
int main() {
    while(~scanf("%lld%lld",&n,&m)){
        for(int i = 1; i <= 4e5 + 2500; i++)
            fa[i] = i;
        cnt = 1;
        for(int i = 1; i <= n; i++){
            scanf("%lld",&g[i].val);g[i].id = i;
        }
        sort(g + 1,g + 1 + n,cmp1);
        ll id1 = g[1].id;
//        cout << id1 <<endl;
        for(int i = 2; i <= n; i++) {
            gg[cnt].u = g[1].id;
            gg[cnt].v = g[i].id;
            gg[cnt++].w = g[1].val + g[i].val;
//            id1 = g[i].id;
            if(i == 7 ){
//                cout << gg[cnt - 1].u << "    asdasda   " << gg[cnt - 1].v << "    " <<gg[cnt].w << endl;
            }
        }
        for(int i = 1; i <= m; i++) {
            ll u,v,w;
            scanf("%lld%lld%lld",&u,&v,&w);

//            cin >> u >> v >> w;
            gg[cnt].u = u;
            gg[cnt].v = v;
            gg[cnt++].w = w;
        }
        sort(gg + 1,gg + cnt,cmp2);
        printf("%lld\n",krus());
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int>  P;
vector<vector<ll> >v;
const int maxn = 2e6;
ll ans[maxn];
ll val[maxn];
ll n,m;
struct node1 {
    ll u,v,w;
} gg[maxn];

struct node {
    ll id, val;
} g[maxn];
int cnt = 0;

bool cmp1(struct node a,struct node b) {
    return a.val < b.val;
}
int fa[maxn];
int Find(int x) {
    if(x == fa[x]) return x;
    return Find(fa[x]);
}
bool cmp2(struct node1 a,struct node1 b) {
    return a.w < b.w;
}
int krus() {
    ll ans = 0;
//    cout << cnt << endl;
    for(int i = 1; i < cnt; i++) {
        int u = gg[i].u;
        int v = gg[i].v;
        int U = Find(u);
        int V = Find(v);
        if(U != V) {
//        cout << U << "   " << V << endl;
            fa[U] = V;
            ans += gg[i].w;
        }
    }
    return ans;
}
int main() {
    ios::sync_with_stdio(false);
    while(cin >> n >> m ) {
        for(int i = 1; i <= 4e5 + 2500; i++)
            fa[i] = i;
        cnt = 1;
        for(int i = 1; i <= n; i++) cin >> g[i].val,g[i].id = i;
        sort(g + 1,g + 1 + n,cmp1);
        ll id1 = g[1].id;
//        cout << id1 <<endl;
        for(int i = 2; i <= n; i++) {
            gg[cnt].u = g[1].id;
            gg[cnt].v = g[i].id;
            gg[cnt++].w = g[1].val + g[i].val;
//            id1 = g[i].id;
            if(i == 7 ){
//                cout << gg[cnt - 1].u << "    asdasda   " << gg[cnt - 1].v << "    " <<gg[cnt].w << endl;
            }
        }
        for(int i = 1; i <= m; i++) {
            ll u,v,w;
            cin >> u >> v >> w;
            gg[cnt].u = u;
            gg[cnt].v = v;
            gg[cnt++].w = w;
        }
        sort(gg + 1,gg + cnt,cmp2);
        for(int i = 1; i < cnt; i++) {
//            cout <<gg[i].v << "   " <<gg[i].u << "   " <<gg[i].w <<endl;
        }
        cout << krus() << endl;
    }
    return 0;
}

//
//
//
//
//
//
//
//#include<stdio.h>
//#include<iostream>
//#include<algorithm>
//using namespace std;
//const int maxn =1e6+10;
//typedef long long ll;
//int pre[maxn];
//int u[maxn],v[maxn],r[maxn];
//ll w[maxn];//u,v表示第i条边起点终点，r用来存下标
//ll ans;
//int n,m;
//bool cmp2(int a,int b)
//{
//    return w[a]<w[b];
//}
//int find(int x)
//{
//    if(pre[x]!=x)
//        pre[x]=find(pre[x]);
//        return pre[x];
//}
//void tree()
//{
//    int cnt=0;
//    for(int i=1;i<=m;i++) r[i]=i;
//    sort(r+1,r+1+m,cmp2);//每一次放入权值最小的边
//    for(int i = 1;i <= m;i++){
//        cout << v[r[i]] << "   " << u[r[i]] << "  " << w[r[i]] << endl;
//    }
//    for(int i=1;i<=m;i++)
//    {
//        int bow=r[i];
//        int p=find(u[bow]);
//        int q=find(v[bow]);
//        if(p!=q)
//        {
//            pre[p]=q;
//            cnt++;//最小生成树边数
//            ans+=w[bow];//最小花费
//        }
//    }
//    return ;
//}
//struct data
//{
//    int id;
//    ll val;
//}x[maxn];
//bool cmp(const data &a,const data &b)
//{
//    return a.val<b.val;
//}
//int main()
//{
//    scanf("%d%d",&n,&m);
//    for(int i=1;i<=n;i++)
//    {
//        scanf("%lld",&x[i].val);
//        x[i].id=i;
//        pre[i]=i;
//    }
//    sort(x+1,x+1+n,cmp);
//    int pos=x[1].id;
//    for(int i=2;i<=n;i++)
//    {
//        u[i-1]=pos;
//        v[i-1]=x[i].id;
//        w[i-1]=x[1].val+x[i].val;
//    }
//    m+=n-1;
//    for(int i=n;i<=m;i++)
//    {
//        scanf("%d%d%lld",&u[i],&v[i],&w[i]);
//    }
//    tree();
//    printf("%lld\n",ans);
//    return 0;
//}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>

#define maxN 200001
#define maxA 99999999999999999
#define V first
#define Cost second

typedef long maxn;
typedef long long maxa;
typedef std::pair <maxn, maxa> ad_t, pq_t;

maxn n;
maxa a[maxN], mn[maxN];
bool done[maxN];
std::vector <ad_t> ad[maxN];

void Prepare() {
    maxn W = 0;
    std::cin >> n >> W;

    for(maxn i = 0; i < n; i++) std::cin >> a[i];

    for(maxn i = 0; i < W; i++) {
        maxn u, v; maxa w;
        std::cin >> u >> v >> w;
        --u, --v;
        ad[u].push_back(ad_t(v, w));
        ad[v].push_back(ad_t(u, w));
    }

    maxn mn = std::min_element(a, a + n) - a;
    for(maxn i = 0; i < n; i++) {
        if (i == mn) continue;
        ad[i].push_back(ad_t(mn, a[mn] + a[i]));
        ad[mn].push_back(ad_t(i, a[i] + a[mn]));
    }
}

class cmp {
public:
    bool operator()(const pq_t &p1, const pq_t &p2) {
        return p1.Cost > p2.Cost;
    }
};
std::priority_queue <pq_t, std::vector <pq_t>, cmp > pq;

maxa Prim() {
    pq = std::priority_queue <pq_t, std::vector <pq_t>, cmp >();
    std::fill(done, done + n, 0);
    std::fill(mn, mn + n, maxA);

    maxa re = 0;
    mn[0] = 0;
    pq.push(pq_t(0, mn[0]));

    for(maxn i = 0; i < n; i++) {
        maxn u = pq.top().V; pq.pop();
        re += mn[u];

        for(maxn i = 0; i < ad[u].size(); i++) {
            maxn v = ad[u][i].V; maxa c = ad[u][i].Cost;
            if (mn[v] <= c) continue;
            mn[v] = c;
            pq.push(pq_t(v, mn[v]));
        }

        while (pq.top().Cost != mn[pq.top().V]) pq.pop();
    }

    return re;
}

void Process() {
    std::cout << Prim();
}

int main() {
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);

    Prepare();
    Process();
}


#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>

#define maxN 200001
#define maxM 200001
#define vert first
#define cost second

typedef long maxn, maxm;
typedef long long maxa;
typedef std::pair <maxn, maxa> ad_t, pq_t;

maxn n, id[maxN];
maxa a[maxN], res;
std::vector <ad_t> ad[maxN];

bool cmp_id(const maxn& x, const maxn& y) {
	return a[x] < a[y];
}

void Prepare() {
	maxm m = 0;
	std::cin >> n >> m;
	for (maxn i = 0; i < n; i++) std::cin >> a[i], id[i] = i;
	std::sort(id, id + n);

	while (m--) {
		maxn u, v; maxa w;
		std::cin >> u >> v >> w;
		--u, --v;
		ad[u].push_back(ad_t(v, w));
		ad[v].push_back(ad_t(u, w));
	}

	for (maxn i = 1; i < n; i++) {
		ad[id[i]].push_back(ad_t(id[0], a[id[0]] + a[id[i]]));
		ad[id[0]].push_back(ad_t(id[i], a[id[0]] + a[id[i]]));
	}
}

class cmp_pq {
public:
	bool operator() (const pq_t& p1, const pq_t& p2) {
		return p1.cost > p2.cost;
	}
};
std::priority_queue <pq_t, std::vector <pq_t>, cmp_pq > pq;
bool done[maxN];

void Fill(const maxn u) {
	for (maxm i = 0; i < ad[u].size(); i++) {
		maxn v = ad[u][i].vert;
		if (!done[v]) pq.push(pq_t(v, ad[u][i].cost));
	}
}

void Prim() {
	pq.push(pq_t(id[0], 0));
	res = 0;

	for (maxn i = 0; i < n; i++) {
		while (done[pq.top().vert]) pq.pop();
		maxn u = pq.top().vert;
		res += pq.top().cost;
		pq.pop();

		done[u] = 1;
		Fill(u);
	}
}

void Process() {
	Prim();
	std::cout << res;
}

int main() {
	std::ios_base::sync_with_stdio(0);
	std::cin.tie(0);

	Prepare();
	Process();
}


#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>

#define maxN 200001
#define maxM 200001
#define vert first
#define cost second

typedef long maxn, maxm;
typedef long long maxa;
typedef std::pair <maxn, maxa> ad_t, pq_t;

maxn n, id[maxN];
maxa a[maxN], res;
std::vector <ad_t> ad[maxN];

bool cmp_id(const maxn& x, const maxn& y) {
	return a[x] < a[y];
}

void Prepare() {
	maxm m = 0;
	std::cin >> n >> m;
	for (maxn i = 0; i < n; i++) std::cin >> a[i], id[i] = i;
	std::sort(id, id + n, cmp_id);

	while (m--) {
		maxn u, v; maxa w;
		std::cin >> u >> v >> w;
		--u, --v;
		ad[u].push_back(ad_t(v, w));
		ad[v].push_back(ad_t(u, w));
	}

	for (maxn i = 1; i < n; i++) {
		ad[id[i]].push_back(ad_t(id[0], a[id[0]] + a[id[i]]));
		ad[id[0]].push_back(ad_t(id[i], a[id[0]] + a[id[i]]));
	}
}

class cmp_pq {
public:
	bool operator() (const pq_t& p1, const pq_t& p2) {
		return p1.cost > p2.cost;
	}
};
std::priority_queue <pq_t, std::vector <pq_t>, cmp_pq > pq;
bool done[maxN];

void Fill(const maxn u) {
	for (maxm i = 0; i < ad[u].size(); i++) {
		maxn v = ad[u][i].vert;
		if (!done[v]) pq.push(pq_t(v, ad[u][i].cost));
	}
}

void Prim() {
	pq.push(pq_t(id[0], 0));
	res = 0;

	for (maxn i = 0; i < n; i++) {
		while (done[pq.top().vert]) pq.pop();
		maxn u = pq.top().vert;
		res += pq.top().cost;
		pq.pop();

		done[u] = 1;
		Fill(u);
	}
}

void Process() {
	Prim();
	std::cout << res;
}

int main() {
	std::ios_base::sync_with_stdio(0);
	std::cin.tie(0);

	Prepare();
	Process();
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>

#define maxN 200001
#define maxA 99999999999999999
#define V first
#define Cost second

typedef long maxn;
typedef long long maxa;
typedef std::pair <maxn, maxa> ad_t, pq_t;

maxn n;
maxa a[maxN];
bool done[maxN];
std::vector <ad_t> ad[maxN];

void Prepare() {
    maxn W = 0;
    std::cin >> n >> W;

    for(maxn i = 0; i < n; i++) std::cin >> a[i];

    for(maxn i = 0; i < W; i++) {
        maxn u, v; maxa w;
        std::cin >> u >> v >> w;
        --u, --v;
        ad[u].push_back(ad_t(v, w));
        ad[v].push_back(ad_t(u, w));
    }

    maxn mn = std::min_element(a, a + n) - a;
    for(maxn i = 0; i < n; i++) {
        if (i == mn) continue;
        ad[i].push_back(ad_t(mn, a[mn] + a[i]));
        ad[mn].push_back(ad_t(i, a[i] + a[mn]));
    }
}

class cmp {
public:
    bool operator()(const pq_t &p1, const pq_t &p2) {
        return p1.Cost > p2.Cost;
    }
};
std::priority_queue <pq_t, std::vector <pq_t>, cmp > pq;

maxa Prim() {
    pq = std::priority_queue <pq_t, std::vector <pq_t>, cmp >();
    std::fill(done, done + n, 0);

    maxa re = 0;
    pq.push(pq_t(0, 0));

    for(maxn i = 0; i < n; i++) {
        while (done[pq.top().V]) pq.pop();

        maxn u = pq.top().V;
        done[u] = 1;
        re += pq.top().Cost;
        pq.pop();

        for(maxn i = 0; i < ad[u].size(); i++) {
            maxn v = ad[u][i].V; maxa c = ad[u][i].Cost;
            if (done[v]) continue;
            pq.push(pq_t(v, c));
        }
    }

    return re;
}

void Process() {
    std::cout << Prim();
}

int main() {
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);

    Prepare();
    Process();
}


#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>

#define maxN 200001
#define maxM 200001
#define vert first
#define cost second

typedef long maxn, maxm;
typedef long long maxa;
typedef std::pair <maxn, maxa> ad_t, pq_t;

maxn n, id[maxN];
maxa a[maxN], res;
std::vector <ad_t> ad[maxN];

bool cmp_id(const maxn& x, const maxn& y) {
	return a[x] < a[y];
}

void Prepare() {
	maxm m = 0;
	std::cin >> n >> m;
	for (maxn i = 0; i < n; i++) std::cin >> a[i], id[i] = i;
	std::sort(id, id + n);

	while (m--) {
		maxn u, v; maxa w;
		std::cin >> u >> v >> w;
		--u, --v;
		ad[u].push_back(ad_t(v, w));
		ad[v].push_back(ad_t(u, w));
	}

	for (maxn i = 1; i < n; i++) {
		ad[id[i]].push_back(ad_t(id[0], a[id[0]] + a[id[i]]));
		ad[id[0]].push_back(ad_t(id[i], a[id[0]] + a[id[i]]));
	}
}

class cmp_pq {
public:
	bool operator() (const pq_t& p1, const pq_t& p2) {
		return p1.cost > p2.cost;
	}
};
std::priority_queue <pq_t, std::vector <pq_t>, cmp_pq > pq;
bool done[maxN];

void Fill(const maxn u) {
	for (maxm i = 0; i < ad[u].size(); i++) {
		maxn v = ad[u][i].vert;
		if (!done[v]) pq.push(pq_t(v, ad[u][i].cost));
	}
}

void Prim() {
	pq.push(pq_t(id[0], 0));
	res = 0;

	for (maxn i = 0; i < n; i++) {
		while (done[pq.top().vert]) pq.pop();
		maxn u = pq.top().vert;
		res += pq.top().cost;
		pq.pop();

		done[u] = 1;
		Fill(i);
	}
}

void Process() {
	Prim();
	std::cout << res;
}

int main() {
	std::ios_base::sync_with_stdio(0);
	std::cin.tie(0);

	Prepare();
	Process();
}


#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>

#define maxN 200001
#define maxM 200001
#define vert first
#define cost second

typedef long maxn, maxm;
typedef long long maxa;
typedef std::pair <maxn, maxa> ad_t, pq_t;

maxn n, id[maxN];
maxa a[maxN], res;
std::vector <ad_t> ad[maxN];

bool cmp_id(const maxn& x, const maxn& y) {
	return a[x] < a[y];
}

void Prepare() {
	maxm m = 0;
	std::cin >> n >> m;
	for (maxn i = 0; i < n; i++) std::cin >> a[i], id[i] = i;
	std::sort(a, a + n);

	while (m--) {
		maxn u, v; maxa w;
		std::cin >> u >> v >> w;
		--u, --v;
		ad[u].push_back(ad_t(v, w));
		ad[v].push_back(ad_t(u, w));
	}

	for (maxn i = 1; i < n; i++) {
		ad[id[i]].push_back(ad_t(id[0], a[id[0]] + a[id[i]]));
		ad[id[0]].push_back(ad_t(id[i], a[id[0]] + a[id[i]]));
	}
}

class cmp_pq {
public:
	bool operator() (const pq_t& p1, const pq_t& p2) {
		return p1.cost > p2.cost;
	}
};
std::priority_queue <pq_t, std::vector <pq_t>, cmp_pq > pq;
bool done[maxN];

void Fill(const maxn u) {
	for (maxm i = 0; i < ad[u].size(); i++) {
		maxn v = ad[u][i].vert;
		if (!done[v]) pq.push(pq_t(v, ad[u][i].cost));
	}
}

void Prim() {
	pq.push(pq_t(id[0], 0));
	res = 0;

	for (maxn i = 0; i < n; i++) {
		while (done[pq.top().vert]) pq.pop();
		maxn u = pq.top().vert;
		res += pq.top().cost;
		pq.pop();

		done[u] = 1;
		Fill(i);
	}
}

void Process() {
	Prim();
	std::cout << res;
}

int main() {
	std::ios_base::sync_with_stdio(0);
	std::cin.tie(0);

	Prepare();
	Process();
}


#include<iostream>
#include<vector>
#include <algorithm>

using std::vector;
using std::pair;
using std::make_pair;

struct Sale {
public:
    int v1 = -1;
    int v2 = -1;
    long long cost = 0;
};

struct Vertex {
public:
    long long cost = 0;
    int number = -1;
 };

long long MST(vector<Sale> sales, vector<Vertex> vert, int minVert, int nVert);
 void do1parent(vector<pair<int, int>> status, int nVert);
int do1parentRec(int vertex, vector<pair<int, int>> status);
void merge(int v1, int v2, vector<pair<int, int> >& status);
int getParet(int vertex, vector<pair<int, int> >& status);

int main() {
    int nVert = 0;
    int nSales = 0;
    std::cin >> nVert >> nSales;
    vector<Vertex> vert(nVert);
    int minVert = 0;
    for (int i = 0; i < nVert; i++) {
        vert[i].number = i;
        std::cin >> vert[i].cost;
        if (vert[i].cost < vert[minVert].cost) {
            minVert = i;
        }
    }
    Sale s;
    vector<Sale> sales;
    for (int i = 0; i < nSales; i++) {
        std::cin >> s.v1 >> s.v2 >> s.cost;
        s.v1--;
        s.v2--;
        if ((s.cost < vert[minVert].cost + vert[s.v1].cost) || (s.cost < vert[minVert].cost + vert[s.v2].cost)) {
            sales.push_back(s);
        }
    }
    std::cout << MST(sales, vert, minVert, nVert) << std::endl;
    return 0;
}

long long MST(vector<Sale> sales, vector<Vertex> vert, int minVert, int nVert) {
    vector<pair<int, int>> status(nVert);
    for(int i = 0; i < nVert; ++i) {
        status[i].first = i;
        status[i].second = 0;
    }
    long long MSTweight = 0;
    for (int i = 0; i < sales.size(); ++i) {
        if (getParet(sales[i].v1, status) != getParet(sales[i].v2, status)) {
            MSTweight += sales[i].cost;
            merge(getParet(sales[i].v1, status), getParet(sales[i].v2, status), status);
        }
    }
    do1parent(status, nVert);
    vector<int> minInGroup(nVert, -1);
    for (int i = 0; i < nVert; ++i) {
        if((minInGroup[status[i].first] == -1) || (minInGroup[status[i].first] > vert[i].cost)) {
            minInGroup[status[i].first] = vert[i].cost;
        }
    }
    for (int i = 0; i < nVert; ++i) {
        if(minInGroup[i] != -1) {
            MSTweight = MSTweight + vert[minVert].cost + minInGroup[i];
        }
    }
    MSTweight -= 2 * vert[minVert].cost;
    return MSTweight;
}

void do1parent(vector<pair<int, int>> status, int nVert) {
    for(int i = 0; i < nVert; i++) {
        do1parentRec(i, status);
    }

}

int do1parentRec(int vertex, vector<pair<int, int>> status) {
    if(status[vertex].first == vertex) {
        return vertex;
    }
    status[vertex].first = do1parentRec(status[vertex].first, status);
    return status[vertex].first;
}

void merge(int v1, int v2, vector<pair<int, int> >& status) {
    if (status[v1].second > status[v2].second) {
        status[v2].first = v1;
        status[v1].second = std::max(status[v1].second, status[v2].second + 1);
    } else {
        status[v1].first = v2;
        status[v2].second = std::max(status[v2].second, status[v1].second + 1);
    }
}

int getParet(int vertex, vector<pair<int, int> >& status) {
    if(status[vertex].first == vertex) {
        return vertex;
    } else {
        return getParet(status[vertex].first, status);
    }
}


#include<iostream>
#include<vector>

using std::vector;
using std::pair;

struct Edge {
public:
    int from = 0;
    int to = 0;
    long long weight = 0;
};

int myComp(const void *a, const void *b);
long long MST(Edge* edges, int nVert, int nEdges);
void merge(int v1, int v2, vector<pair<int, int> >& status);
int getParet(int vertex, vector<pair<int, int> >& status);

int main(){
    int nVert = 0;
    int nSales = 0;
    std::cin >> nVert >> nSales;
    Edge* edges = new Edge[nSales + nVert * nVert];
    vector<int> cost(nVert, -1);
    int minVert = -1;
    int minWeight = -1;
    for (int i = 0; i < nVert; i++) {
        std::cin >> cost[i];
        if (minVert == -1 || minWeight > cost[i]) {
            minVert = i;
            minWeight = cost[i];
        }
    }
    for (int i = 0; i < nSales; ++i) {
        std::cin >> edges[i].from >> edges[i].to >> edges[i].weight;
        edges[i].from--;
        edges[i].to--;
    }
    int position = nSales;
    for (int i = 0; i < nVert; ++i) {
        edges[position].from = minVert;
        edges[position].to = i;
        edges[position].weight = cost[i] + minWeight;
        position++;
    }
    std::cout << MST(edges, nVert, nSales + nVert * nVert) << std::endl;
    delete[] edges;
    return 0;
}

int myComp(const void *a, const void *b) {
    Edge arg1 = *static_cast<const Edge*>(a);
    Edge arg2 = *static_cast<const Edge*>(b);
    return arg1.weight - arg2.weight;
}

long long MST(Edge* edges, int nVert, int nEdges) {
    std::qsort(edges, nEdges, sizeof(Edge), myComp);
    long long MSTweight = 0;
    vector<pair<int, int> > status(nVert);
    for (int i  = 0; i < nVert; ++i) {
        status[i].first = i;
        status[i].second = 0;
    }
    for (int i = 0; i < nEdges; ++i) {
        if (getParet(edges[i].from, status) != getParet(edges[i].to, status)) {
            MSTweight += edges[i].weight;
            merge(getParet(edges[i].from, status), getParet(edges[i].to, status), status);
        }
    }
    return MSTweight;
}

void merge(int v1, int v2, vector<pair<int, int> >& status) {
    if (status[v1].second > status[v2].second) {
        status[v2].first = v1;
        status[v1].second = std::max(status[v1].second, status[v2].second + 1);
    } else {
        status[v1].first = v2;
        status[v2].second = std::max(status[v2].second, status[v1].second + 1);
    }
}

int getParet(int vertex, vector<pair<int, int> >& status) {
    if(status[vertex].first == vertex) {
        return vertex;
    } else {
        return getParet(status[vertex].first, status);
    }
}


#include<iostream>
#include<vector>

using std::vector;
using std::pair;

struct Edge {
public:
    int from = 0;
    int to = 0;
    long long weight = 0;
};

int myComp(const void *a, const void *b);
long long MST(Edge* edges, int nVert, int nEdges);
void merge(int v1, int v2, vector<pair<int, int> >& status);
int getParet(int vertex, vector<pair<int, int> >& status);

int main(){
    int nVert = 0;
    int nSales = 0;
    std::cin >> nVert >> nSales;
    Edge* edges = new Edge[nSales + nVert];
    vector<int> cost(nVert, -1);
    int minVert = -1;
    int minWeight = -1;
    for (int i = 0; i < nVert; i++) {
        std::cin >> cost[i];
        if (minVert == -1 || minWeight > cost[i]) {
            minVert = i;
            minWeight = cost[i];
        }
    }
    for (int i = 0; i < nSales; ++i) {
        std::cin >> edges[i].from >> edges[i].to >> edges[i].weight;
        edges[i].from--;
        edges[i].to--;
    }
    int position = nSales;
    for (int i = 0; i < nVert; ++i) {
        edges[position].from = minVert;
        edges[position].to = i;
        edges[position].weight = cost[i] + minWeight;
        position++;
    }
    std::cout << MST(edges, nVert, nSales + nVert) << std::endl;
    delete[] edges;
    return 0;
}

int myComp(const void *a, const void *b) {
    Edge arg1 = *static_cast<const Edge*>(a);
    Edge arg2 = *static_cast<const Edge*>(b);
    if (arg1.weight > arg2.weight) {
        return 1;
    }
    if (arg1.weight == arg2.weight) {
        return 0;
    }
    return -1;
}

long long MST(Edge* edges, int nVert, int nEdges) {
    std::qsort(edges, nEdges, sizeof(Edge), myComp);
    long long MSTweight = 0;
    vector<pair<int, int> > status(nVert);
    for (int i  = 0; i < nVert; ++i) {
        status[i].first = i;
        status[i].second = 0;
    }
    for (int i = 0; i < nEdges; ++i) {
        if (getParet(edges[i].from, status) != getParet(edges[i].to, status)) {
            MSTweight += edges[i].weight;
            merge(getParet(edges[i].from, status), getParet(edges[i].to, status), status);
        }
    }
    return MSTweight;
}

void merge(int v1, int v2, vector<pair<int, int> >& status) {
    if (status[v1].second > status[v2].second) {
        status[v2].first = v1;
        status[v1].second = std::max(status[v1].second, status[v2].second + 1);
    } else {
        status[v1].first = v2;
        status[v2].second = std::max(status[v2].second, status[v1].second + 1);
    }
}

int getParet(int vertex, vector<pair<int, int> >& status) {
    if(status[vertex].first == vertex) {
        return vertex;
    } else {
        return getParet(status[vertex].first, status);
    }
}


#include<iostream>
#include<vector>

using std::vector;
using std::pair;

struct Edge {
public:
    int from = 0;
    int to = 0;
    long long weight = 0;
};

int myComp(const void *a, const void *b);
long long MST(Edge* edges, int nVert, int nEdges);
void merge(int v1, int v2, vector<pair<int, int> >& status);
int getParet(int vertex, vector<pair<int, int> >& status);

int main(){
    int nVert = 0;
    int nSales = 0;
    std::cin >> nVert >> nSales;
    Edge* edges = new Edge[nSales + nVert - 1];
    vector<long long> cost(nVert, -1);
    int minVert = 0;
    for (int i = 0; i < nVert; i++) {
        std::cin >> cost[i];
        if (cost[minVert] > cost[i]) {
            minVert = i;
        }
    }
    for (int i = 0; i < nSales; ++i) {
        std::cin >> edges[i].from >> edges[i].to >> edges[i].weight;
        edges[i].from--;
        edges[i].to--;
    }
    int position = nSales;
    for (int i = 0; i < nVert; ++i) {
        if (i != minVert) {
            edges[position].from = minVert;
            edges[position].to = i;
            edges[position].weight = cost[i] + cost[minVert];
            position++;
        }
    }
    std::cout << MST(edges, nVert, nSales + nVert - 1) << std::endl;
    delete[] edges;
    return 0;
}

int myComp(const void *a, const void *b) {
    Edge arg1 = *static_cast<const Edge*>(a);
    Edge arg2 = *static_cast<const Edge*>(b);
    if (arg1.weight > arg2.weight) {
        return 1;
    }
    if (arg1.weight == arg2.weight) {
        return 0;
    }
    return -1;
}

long long MST(Edge* edges, int nVert, int nEdges) {
    std::qsort(edges, nEdges, sizeof(Edge), myComp);
    long long MSTweight = 0;
    vector<pair<int, int> > status(nVert);
    for (int i  = 0; i < nVert; ++i) {
        status[i].first = i;
        status[i].second = 0;
    }
    for (int i = 0; i < nEdges; ++i) {
        if (getParet(edges[i].from, status) != getParet(edges[i].to, status)) {
            MSTweight += edges[i].weight;
            merge(getParet(edges[i].from, status), getParet(edges[i].to, status), status);
        }
    }
    return MSTweight;
}

void merge(int v1, int v2, vector<pair<int, int> >& status) {
    if (status[v1].second > status[v2].second) {
        status[v2].first = v1;
        status[v1].second = std::max(status[v1].second, status[v2].second + 1);
    } else {
        status[v1].first = v2;
        status[v2].second = std::max(status[v2].second, status[v1].second + 1);
    }
}

int getParet(int vertex, vector<pair<int, int> >& status) {
    if(status[vertex].first == vertex) {
        return vertex;
    } else {
        return getParet(status[vertex].first, status);
    }
}


#include<iostream>
#include<vector>

using std::vector;
using std::pair;

struct Edge {
public:
    int from = 0;
    int to = 0;
    long long weight = 0;
};

int myComp(const void *a, const void *b);
long long MST(Edge* edges, long long nVert, long long nEdges);
void merge(int v1, int v2, vector<pair<int, int> >& status);
int getParet(int vertex, vector<pair<int, int> >& status);

int main(){
    long long nVert = 0;
    long long nSales = 0;
    std::cin >> nVert >> nSales;
    Edge* edges = new Edge[nSales + nVert * nVert];
    vector<int> cost(nVert, -1);
    int minVert = -1;
    int minWeight = -1;
    for (int i = 0; i < nVert; i++) {
        std::cin >> cost[i];
        if (minVert == -1 || minWeight > cost[i]) {
            minVert = i;
            minWeight = cost[i];
        }
    }
    for (int i = 0; i < nSales; ++i) {
        std::cin >> edges[i].from >> edges[i].to >> edges[i].weight;
        edges[i].from--;
        edges[i].to--;
    }
    int position = nSales;
    for (int i = 0; i < nVert; ++i) {
        edges[position].from = minVert;
        edges[position].to = i;
        edges[position].weight = cost[i] + minWeight;
        position++;
    }
    std::cout << MST(edges, nVert, nSales + nVert * nVert) << std::endl;
    delete[] edges;
    return 0;
}

int myComp(const void *a, const void *b) {
    Edge arg1 = *static_cast<const Edge*>(a);
    Edge arg2 = *static_cast<const Edge*>(b);
    return arg1.weight - arg2.weight;
}

long long MST(Edge* edges, long long nVert, long long nEdges) {
    std::qsort(edges, nEdges, sizeof(Edge), myComp);
    long long MSTweight = 0;
    vector<pair<int, int> > status(nVert);
    for (int i  = 0; i < nVert; ++i) {
        status[i].first = i;
        status[i].second = 0;
    }
    for (int i = 0; i < nEdges; ++i) {
        if (getParet(edges[i].from, status) != getParet(edges[i].to, status)) {
            MSTweight += edges[i].weight;
            merge(getParet(edges[i].from, status), getParet(edges[i].to, status), status);
        }
    }
    return MSTweight;
}

void merge(int v1, int v2, vector<pair<int, int> >& status) {
    if (status[v1].second > status[v2].second) {
        status[v2].first = v1;
        status[v1].second = std::max(status[v1].second, status[v2].second + 1);
    } else {
        status[v1].first = v2;
        status[v2].second = std::max(status[v2].second, status[v1].second + 1);
    }
}

int getParet(int vertex, vector<pair<int, int> >& status) {
    if(status[vertex].first == vertex) {
        return vertex;
    } else {
        return getParet(status[vertex].first, status);
    }
}


#include<iostream>
#include<vector>

using std::vector;
using std::pair;

struct Edge {
public:
    int from = 0;
    int to = 0;
    long long weight = 0;
};

int myComp(const void *a, const void *b);
long long MST(Edge* edges, int nVert, int nEdges);
void merge(int v1, int v2, vector<pair<int, int> >& status);
int getParet(int vertex, vector<pair<int, int> >& status);

int main(){
    int nVert = 0;
    int nSales = 0;
    std::cin >> nVert >> nSales;
    Edge* edges = new Edge[nSales + nVert];
    vector<long long> cost(nVert, -1);
    int minVert = -1;
    int minWeight = -1;
    for (int i = 0; i < nVert; i++) {
        std::cin >> cost[i];
        if (minVert == -1 || minWeight > cost[i]) {
            minVert = i;
            minWeight = cost[i];
        }
    }
    for (int i = 0; i < nSales; ++i) {
        std::cin >> edges[i].from >> edges[i].to >> edges[i].weight;
        edges[i].from--;
        edges[i].to--;
    }
    int position = nSales;
    for (int i = 0; i < nVert; ++i) {
        edges[position].from = minVert;
        edges[position].to = i;
        edges[position].weight = cost[i] + minWeight;
        position++;
    }
    std::cout << MST(edges, nVert, nSales + nVert) << std::endl;
    delete[] edges;
    return 0;
}

int myComp(const void *a, const void *b) {
    Edge arg1 = *static_cast<const Edge*>(a);
    Edge arg2 = *static_cast<const Edge*>(b);
    if (arg1.weight > arg2.weight) {
        return 1;
    }
    if (arg1.weight == arg2.weight) {
        return 0;
    }
    return -1;
}

long long MST(Edge* edges, int nVert, int nEdges) {
    std::qsort(edges, nEdges, sizeof(Edge), myComp);
    long long MSTweight = 0;
    vector<pair<int, int> > status(nVert);
    for (int i  = 0; i < nVert; ++i) {
        status[i].first = i;
        status[i].second = 0;
    }
    for (int i = 0; i < nEdges; ++i) {
        if (getParet(edges[i].from, status) != getParet(edges[i].to, status)) {
            MSTweight += edges[i].weight;
            merge(getParet(edges[i].from, status), getParet(edges[i].to, status), status);
        }
    }
    return MSTweight;
}

void merge(int v1, int v2, vector<pair<int, int> >& status) {
    if (status[v1].second > status[v2].second) {
        status[v2].first = v1;
        status[v1].second = std::max(status[v1].second, status[v2].second + 1);
    } else {
        status[v1].first = v2;
        status[v2].second = std::max(status[v2].second, status[v1].second + 1);
    }
}

int getParet(int vertex, vector<pair<int, int> >& status) {
    if(status[vertex].first == vertex) {
        return vertex;
    } else {
        return getParet(status[vertex].first, status);
    }
}


#include<iostream>
#include<vector>

using std::vector;
using std::pair;

struct Edge {
public:
    long long from = 0;
    long long to = 0;
    long long weight = 0;
};

int myComp(const void *a, const void *b);
long long MST(Edge* edges, long long nVert, long long nEdges);
void merge(long long v1, long long v2, vector<pair<long long, long long> >& status);
long long getParet(long long vertex, vector<pair<long long, long long> >& status);

int main(){
    long long nVert = 0;
    long long nSales = 0;
    std::cin >> nVert >> nSales;
    Edge* edges = new Edge[nSales + nVert * nVert];
    vector<long long> cost(nVert, -1);
    for (long long i = 0; i < nVert; i++) {
        std::cin >> cost[i];
    }
    for (long long i = 0; i < nSales; ++i) {
        std::cin >> edges[i].from >> edges[i].to >> edges[i].weight;
        edges[i].from--;
        edges[i].to--;
    }
    long long position = nSales;
    for (long long i = 0; i < nVert; ++i) {
        for (long long j = 0; j < nVert; ++j) {
            edges[position].from = i;
            edges[position].to = j;
            edges[position].weight = cost[i] + cost[j];
            position++;
        }
    }
    std::cout << MST(edges, nVert, nSales + nVert * nVert) << std::endl;
    delete[] edges;
    return 0;
}

int myComp(const void *a, const void *b) {
    Edge arg1 = *static_cast<const Edge*>(a);
    Edge arg2 = *static_cast<const Edge*>(b);
    if (arg1.weight - arg2.weight > 0) {
        return 1;
    }
    if (arg1.weight == arg2.weight) {
        return 0;
    }
    return -1;
}

long long MST(Edge* edges, long long nVert, long long nEdges) {
    std::qsort(edges, nEdges, sizeof(Edge), myComp);
    long long MSTweight = 0;
    vector<pair<long long, long long> > status(nVert);
    for (long long i  = 0; i < nVert; ++i) {
        status[i].first = i;
        status[i].second = 0;
    }
    for (long long i = 0; i < nEdges; ++i) {
        if (getParet(edges[i].from, status) != getParet(edges[i].to, status)) {
            MSTweight += edges[i].weight;
            merge(getParet(edges[i].from, status), getParet(edges[i].to, status), status);
        }
    }
    return MSTweight;
}

void merge(long long v1, long long v2, vector<pair<long long, long long> >& status) {
    if (status[v1].second > status[v2].second) {
        status[v2].first = v1;
        status[v1].second = std::max(status[v1].second, status[v2].second + 1);
    } else {
        status[v1].first = v2;
        status[v2].second = std::max(status[v2].second, status[v1].second + 1);
    }
}

long long getParet(long long vertex, vector<pair<long long, long long> >& status) {
    if(status[vertex].first == vertex) {
        return vertex;
    } else {
        return getParet(status[vertex].first, status);
    }
}


#include<iostream>
#include<vector>

using std::vector;
using std::pair;

struct Edge {
public:
    int from = 0;
    int to = 0;
    long long weight = 0;
};

int myComp(const void *a, const void *b);
long long MST(Edge* edges, int nVert, int nEdges);
void merge(int v1, int v2, vector<pair<int, int> >& status);
int getParet(int vertex, vector<pair<int, int> >& status);

int main(){
    int nVert = 0;
    int nSales = 0;
    std::cin >> nVert >> nSales;
    Edge* edges = new Edge[nSales + nVert];
    vector<int> cost(nVert, -1);
    int minVert = -1;
    int minWeight = -1;
    for (int i = 0; i < nVert; i++) {
        std::cin >> cost[i];
        if (minVert == -1 || minWeight > cost[i]) {
            minVert = i;
            minWeight = cost[i];
        }
    }
    for (int i = 0; i < nSales; ++i) {
        std::cin >> edges[i].from >> edges[i].to >> edges[i].weight;
        edges[i].from--;
        edges[i].to--;
    }
    int position = nSales;
    for (int i = 0; i < nVert; ++i) {
        edges[position].from = minVert;
        edges[position].to = i;
        edges[position].weight = cost[i] + minWeight;
        position++;
    }
    std::cout << MST(edges, nVert, nSales + nVert) << std::endl;
    delete[] edges;
    return 0;
}

int myComp(const void *a, const void *b) {
    Edge arg1 = *static_cast<const Edge*>(a);
    Edge arg2 = *static_cast<const Edge*>(b);
    return arg1.weight - arg2.weight;
}

long long MST(Edge* edges, int nVert, int nEdges) {
    std::qsort(edges, nEdges, sizeof(Edge), myComp);
    long long MSTweight = 0;
    vector<pair<int, int> > status(nVert);
    for (int i  = 0; i < nVert; ++i) {
        status[i].first = i;
        status[i].second = 0;
    }
    for (int i = 0; i < nEdges; ++i) {
        if (getParet(edges[i].from, status) != getParet(edges[i].to, status)) {
            MSTweight += edges[i].weight;
            merge(getParet(edges[i].from, status), getParet(edges[i].to, status), status);
        }
    }
    return MSTweight;
}

void merge(int v1, int v2, vector<pair<int, int> >& status) {
    if (status[v1].second > status[v2].second) {
        status[v2].first = v1;
        status[v1].second = std::max(status[v1].second, status[v2].second + 1);
    } else {
        status[v1].first = v2;
        status[v2].second = std::max(status[v2].second, status[v1].second + 1);
    }
}

int getParet(int vertex, vector<pair<int, int> >& status) {
    if(status[vertex].first == vertex) {
        return vertex;
    } else {
        return getParet(status[vertex].first, status);
    }
}


#include<iostream>
#include<vector>

using std::vector;
using std::pair;

struct Edge {
public:
    int from = 0;
    int to = 0;
    long long weight = 0;
};

int myComp(const void *a, const void *b);
long long MST(Edge* edges, int nVert, int nEdges);
void merge(int v1, int v2, vector<pair<int, int> >& status);
int getParet(int vertex, vector<pair<int, int> >& status);

int main(){
    int nVert = 0;
    int nSales = 0;
    std::cin >> nVert >> nSales;
    Edge* edges = new Edge[nSales + nVert];
    vector<int> cost(nVert, -1);
    int minVert = -1;
    int minWeight = -1;
    for (int i = 0; i < nVert; i++) {
        std::cin >> cost[i];
        if (minVert == -1 || minWeight > cost[i]) {
            minVert = i;
            minWeight = cost[i];
        }
    }
    for (int i = 0; i < nSales; ++i) {
        std::cin >> edges[i].from >> edges[i].to >> edges[i].weight;
        edges[i].from--;
        edges[i].to--;
    }
    int position = nSales;
    for (int i = 0; i < nVert; ++i) {
        edges[position].from = minVert;
        edges[position].to = i;
        edges[position].weight = cost[i] + minWeight;
        position++;
    }
    std::cout << MST(edges, nVert, nSales + nVert * nVert) << std::endl;
    delete[] edges;
    return 0;
}

int myComp(const void *a, const void *b) {
    Edge arg1 = *static_cast<const Edge*>(a);
    Edge arg2 = *static_cast<const Edge*>(b);
    return arg1.weight - arg2.weight;
}

long long MST(Edge* edges, int nVert, int nEdges) {
    std::qsort(edges, nEdges, sizeof(Edge), myComp);
    long long MSTweight = 0;
    vector<pair<int, int> > status(nVert);
    for (int i  = 0; i < nVert; ++i) {
        status[i].first = i;
        status[i].second = 0;
    }
    for (int i = 0; i < nEdges; ++i) {
        if (getParet(edges[i].from, status) != getParet(edges[i].to, status)) {
            MSTweight += edges[i].weight;
            merge(getParet(edges[i].from, status), getParet(edges[i].to, status), status);
        }
    }
    return MSTweight;
}

void merge(int v1, int v2, vector<pair<int, int> >& status) {
    if (status[v1].second > status[v2].second) {
        status[v2].first = v1;
        status[v1].second = std::max(status[v1].second, status[v2].second + 1);
    } else {
        status[v1].first = v2;
        status[v2].second = std::max(status[v2].second, status[v1].second + 1);
    }
}

int getParet(int vertex, vector<pair<int, int> >& status) {
    if(status[vertex].first == vertex) {
        return vertex;
    } else {
        return getParet(status[vertex].first, status);
    }
}


#include<iostream>
#include<vector>

using std::vector;
using std::pair;

struct Edge {
public:
    int from = 0;
    int to = 0;
    long long weight = 0;
};

int myComp(const void *a, const void *b);
long long MST(Edge* edges, int nVert, int nEdges);
void merge(int v1, int v2, vector<pair<int, int> >& status);
int getParet(int vertex, vector<pair<int, int> >& status);

int main(){
    int nVert = 0;
    int nSales = 0;
    std::cin >> nVert >> nSales;
    Edge* edges = new Edge[nSales + nVert - 1];
    vector<long long> cost(nVert, -1);
    int minVert = -1;
    int minWeight = -1;
    for (int i = 0; i < nVert; i++) {
        std::cin >> cost[i];
        if (minVert == -1 || minWeight > cost[i]) {
            minVert = i;
            minWeight = cost[i];
        }
    }
    for (int i = 0; i < nSales; ++i) {
        std::cin >> edges[i].from >> edges[i].to >> edges[i].weight;
        edges[i].from--;
        edges[i].to--;
    }
    int position = nSales;
    for (int i = 0; i < nVert; ++i) {
        if (i != minVert) {
            edges[position].from = minVert;
            edges[position].to = i;
            edges[position].weight = cost[i] + minWeight;
            position++;
        }
    }
    std::cout << MST(edges, nVert, nSales + nVert - 1) << std::endl;
    delete[] edges;
    return 0;
}

int myComp(const void *a, const void *b) {
    Edge arg1 = *static_cast<const Edge*>(a);
    Edge arg2 = *static_cast<const Edge*>(b);
    if (arg1.weight > arg2.weight) {
        return 1;
    }
    if (arg1.weight == arg2.weight) {
        return 0;
    }
    return -1;
}

long long MST(Edge* edges, int nVert, int nEdges) {
    std::qsort(edges, nEdges, sizeof(Edge), myComp);
    long long MSTweight = 0;
    vector<pair<int, int> > status(nVert);
    for (int i  = 0; i < nVert; ++i) {
        status[i].first = i;
        status[i].second = 0;
    }
    for (int i = 0; i < nEdges; ++i) {
        if (getParet(edges[i].from, status) != getParet(edges[i].to, status)) {
            MSTweight += edges[i].weight;
            merge(getParet(edges[i].from, status), getParet(edges[i].to, status), status);
        }
    }
    return MSTweight;
}

void merge(int v1, int v2, vector<pair<int, int> >& status) {
    if (status[v1].second > status[v2].second) {
        status[v2].first = v1;
        status[v1].second = std::max(status[v1].second, status[v2].second + 1);
    } else {
        status[v1].first = v2;
        status[v2].second = std::max(status[v2].second, status[v1].second + 1);
    }
}

int getParet(int vertex, vector<pair<int, int> >& status) {
    if(status[vertex].first == vertex) {
        return vertex;
    } else {
        return getParet(status[vertex].first, status);
    }
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <ctime>

#define ll long long
#define pb push_back
#define watch(x) cout << (#x) << " = " << (x) << endl

const int INF = 2e9 + 7;
const int MAXA = 2e5 + 10;
const int MOD = 1e9 + 7;

using namespace std;

typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<ll, ii> II;
typedef vector<int> vi;
typedef vector<ii> vii;

int n, m, p[MAXA], lvl[MAXA];
vector<II> edgeList;
li a[MAXA];
ll ans = 0;
int findSet(int u) {
    return (u == p[u]) ? u : (p[u] = findSet(p[u]));
}
bool isSameSet(int u, int v) {
    return (findSet(u) == findSet(v));
}
void mergeSet(int u, int v) {
    if(!isSameSet(u,v)) {
        u = findSet(u);
        v = findSet(v);
        if(lvl[u] > lvl[v]) p[v] = u;
        else {
            p[u] = v;
            if(lvl[u] == lvl[v]) lvl[v] ++;
        }
    }
}
int main() {
    #ifndef ONLINE_JUDGE
    freopen("in.in", "r", stdin);
    #endif
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    //clock_t clk = clock();
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        p[i] = i;
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a + 1, a + n + 1);
    for(int i = 2; i <= n; i++) {
        edgeList.pb(II(a[i].first + a[1].first, ii(a[i].second, a[1].second)));
        //cout << a[i].first + a[1].first << " " << a[i].second << " " << a[1].second << endl;
    }
    for(int i = 1; i <= m; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        //cout << w << " " << u << " " << v << endl;
        edgeList.pb(II(w,ii(u,v)));
    }
    sort(edgeList.begin(), edgeList.end());
    for(int i = 0; i < edgeList.size(); i++) {
        int u = edgeList[i].second.first;
        int v = edgeList[i].second.second;
        int w = edgeList[i].first;
        if(!isSameSet(u,v)) {
            mergeSet(u,v);
            ans += 1LL*w;
        }
    }
    cout << ans << endl;
    //cerr << "Time (in ms): " << double(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';
    return 0;
}


#include <bits/stdc++.h>

#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()

using namespace std;

struct union_find {
  vector<int> p, child, rank;
  int dsu_size;

  union_find(int dsu_size) : dsu_size(dsu_size) {
    p.assign(dsu_size + 1, 0);
    rank.assign(dsu_size + 1, 0);
    child.assign(dsu_size + 1, 0);
    for (int i = 1; i <= dsu_size; i++) {
      p[i] = i;
      child[i] = 1;
    }
  }

  int find(int i) {
    return (p[i] == i) ? i : (p[i] = find(p[i]));
  }

  bool is_same_set(int x, int y) {
    return find(x) == find(y);
  }

  void merge(int x, int y) {
    if (!is_same_set(x, y)) {
      dsu_size--;
      x = find(x);
      y = find(y);
      if (rank[x] > rank[y]) {
        child[x] += child[y];
        p[y] = x;
      } else {
        p[x] = y;
        child[y] += child[x];
        if (rank[x] == rank[y]) {
          rank[y]++;
        }
      }
    }
  }

  int size(int i) {
    return child[find(i)];
  }

  int num_components() {
    return dsu_size;
  }
};

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string &s) {
  return '"' + s + '"';
}

string to_string(const char *s) {
  return to_string((string)s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;

const int N = 2e5 + 1;
const ll INF = 1e17;

int n, m;
vector<tuple<ll, int, int>> edge;
ll a[N];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  union_find dsu(n);
  ll mn = INF;
  int p = -1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] < mn) {
      mn = a[i];
      p = i;
    }
  }
  for (int i = 1; i <= n; i++) {
    edge.push_back({a[i] + mn, p, i});
  }

  for (int i = 1; i <= m; i++) {
    int u, v;
    ll w;
    cin >> u >> v >> w;
    if (a[u] + a[v] <= w)
      continue;
    edge.push_back({w, u, v});
  }

  sort(all(edge));
  debug(edge);

  ll mst = 0;
  for (int i = 0; i < sz(edge); i++) {
    ll w = get<0>(edge[i]);
    int u = get<1>(edge[i]);
    int v = get<2>(edge[i]);
    if (!dsu.is_same_set(u, v)) {
      mst += w;
      dsu.merge(u, v);
    }
  }
  cout << mst << "\n";
}


#include <bits/stdc++.h>

#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()

using namespace std;

struct union_find {
  vector<int> p, child, rank;
  int dsu_size;

  union_find(int dsu_size) : dsu_size(dsu_size) {
    p.assign(dsu_size + 1, 0);
    rank.assign(dsu_size + 1, 0);
    child.assign(dsu_size + 1, 0);
    for (int i = 1; i <= dsu_size; i++) {
      p[i] = i;
      child[i] = 1;
    }
  }

  int find(int i) {
    return (p[i] == i) ? i : (p[i] = find(p[i]));
  }

  bool is_same_set(int x, int y) {
    return find(x) == find(y);
  }

  void merge(int x, int y) {
    if (!is_same_set(x, y)) {
      dsu_size--;
      x = find(x);
      y = find(y);
      if (rank[x] > rank[y]) {
        child[x] += child[y];
        p[y] = x;
      } else {
        p[x] = y;
        child[y] += child[x];
        if (rank[x] == rank[y]) {
          rank[y]++;
        }
      }
    }
  }

  int size(int i) {
    return child[find(i)];
  }

  int num_components() {
    return dsu_size;
  }
};

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string &s) {
  return '"' + s + '"';
}

string to_string(const char *s) {
  return to_string((string)s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;

const int N = 2e5 + 1;
const ll INF = 1e17;

int n, m;
vector<tuple<ll, int, int>> edge;
int a[N];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  union_find dsu(n);
  ll mn = INF;
  int p = -1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] < mn) {
      mn = a[i];
      p = i;
    }
  }
  for (int i = 1; i <= n; i++) {
    edge.push_back({a[i] + mn, p, i});
  }

  for (int i = 1; i <= m; i++) {
    int u, v;
    ll w;
    cin >> u >> v >> w;
    if (u + v <= w)
      continue;
    edge.push_back({w, u, v});
  }

  sort(all(edge));
  debug(edge);
  ll mst = 0;
  for (int i = 0; i < sz(edge); i++) {
    ll w = get<0>(edge[i]);
    int u = get<1>(edge[i]);
    int v = get<2>(edge[i]);
    if (!dsu.is_same_set(u, v)) {
      mst += w;
      dsu.merge(u, v);
    }
  }
  cout << mst << "\n";
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <ctime>

#define ll long long
#define pb push_back
#define watch(x) cout << (#x) << " = " << (x) << endl

const int INF = 2e9 + 7;
const int MAXA = 2e5 + 10;
const int MOD = 1e9 + 7;

using namespace std;

typedef pair<int, int> ii;
typedef pair<ll, ii> II;
typedef vector<int> vi;
typedef vector<ii> vii;

int n, m, p[MAXA], lvl[MAXA];
vector<II> edgeList;
ii a[MAXA];
ll ans = 0;
int findSet(int u) {
    return (u == p[u]) ? u : (p[u] = findSet(p[u]));
}
bool isSameSet(int u, int v) {
    return (findSet(u) == findSet(v));
}
void mergeSet(int u, int v) {
    if(!isSameSet(u,v)) {
        u = findSet(u);
        v = findSet(v);
        if(lvl[u] > lvl[v]) p[v] = u;
        else {
            p[u] = v;
            if(lvl[u] == lvl[v]) lvl[v] ++;
        }
    }
}
int main() {
    #ifndef ONLINE_JUDGE
    freopen("in.in", "r", stdin);
    #endif
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    //clock_t clk = clock();
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        p[i] = i;
        cin >> a[i].first;
        a[i].second = i;
    }
    for(int i = 2; i <= n; i++) {
        edgeList.pb(II(a[i].first + a[1].first, ii(a[i].second, a[1].second)));
        //cout << a[i].first + a[1].first << " " << a[i].second << " " << a[1].second << endl;
    }
    for(int i = 1; i <= m; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        //cout << w << " " << u << " " << v << endl;
        edgeList.pb(II(w,ii(u,v)));
    }
    sort(edgeList.begin(), edgeList.end());
    for(int i = 0; i < edgeList.size(); i++) {
        int u = edgeList[i].second.first;
        int v = edgeList[i].second.second;
        int w = edgeList[i].first;
        if(!isSameSet(u,v)) {
            mergeSet(u,v);
            ans += w;
        }
    }
    cout << ans << endl;
    //cerr << "Time (in ms): " << double(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';
    return 0;
}


#include <bits/stdc++.h>

#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()

using namespace std;

struct union_find {
  vector<int> p, child, rank;
  int dsu_size;

  union_find(int dsu_size) : dsu_size(dsu_size) {
    p.assign(dsu_size + 1, 0);
    rank.assign(dsu_size + 1, 0);
    child.assign(dsu_size + 1, 0);
    for (int i = 1; i <= dsu_size; i++) {
      p[i] = i;
      child[i] = 1;
    }
  }

  int find(int i) {
    return (p[i] == i) ? i : (p[i] = find(p[i]));
  }

  bool is_same_set(int x, int y) {
    return find(x) == find(y);
  }

  void merge(int x, int y) {
    if (!is_same_set(x, y)) {
      dsu_size--;
      x = find(x);
      y = find(y);
      if (rank[x] > rank[y]) {
        child[x] += child[y];
        p[y] = x;
      } else {
        p[x] = y;
        child[y] += child[x];
        if (rank[x] == rank[y]) {
          rank[y]++;
        }
      }
    }
  }

  int size(int i) {
    return child[find(i)];
  }

  int num_components() {
    return dsu_size;
  }
};

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string &s) {
  return '"' + s + '"';
}

string to_string(const char *s) {
  return to_string((string)s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;

const int N = 2e5 + 1;
const ll INF = 1e17;

int n, m;
vector<tuple<ll, int, int>> edge;
int a[N];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  union_find dsu(n);
  ll mn = INF;
  int p = -1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] < mn) {
      mn = a[i];
      p = i;
    }
  }
  for (int i = 1; i <= n; i++) {
    edge.push_back({a[i] + mn, p, i});
  }

  for (int i = 1; i <= m; i++) {
    int u, v;
    ll w;
    cin >> u >> v >> w;
    if (a[u] + a[v] <= w)
      continue;
    edge.push_back({w, u, v});
  }

  sort(all(edge));
  debug(edge);

  ll mst = 0;
  for (int i = 0; i < sz(edge); i++) {
    ll w = get<0>(edge[i]);
    int u = get<1>(edge[i]);
    int v = get<2>(edge[i]);
    if (!dsu.is_same_set(u, v)) {
      mst += w;
      dsu.merge(u, v);
    }
  }
  cout << mst << "\n";
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <ctime>

#define ll long long
#define pb push_back
#define watch(x) cout << (#x) << " = " << (x) << endl

const int INF = 2e9 + 7;
const int MAXA = 2e5 + 10;
const int MOD = 1e9 + 7;

using namespace std;

typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<ll, ii> II;
typedef vector<int> vi;
typedef vector<ii> vii;

int n, m, p[MAXA], lvl[MAXA];
vector<II> edgeList;
li a[MAXA];
ll ans = 0;
int findSet(int u) {
    return (u == p[u]) ? u : (p[u] = findSet(p[u]));
}
bool isSameSet(int u, int v) {
    return (findSet(u) == findSet(v));
}
void mergeSet(int u, int v) {
    if(!isSameSet(u,v)) {
        u = findSet(u);
        v = findSet(v);
        if(lvl[u] > lvl[v]) p[v] = u;
        else {
            p[u] = v;
            if(lvl[u] == lvl[v]) lvl[v] ++;
        }
    }
}
int main() {
    #ifndef ONLINE_JUDGE
    freopen("in.in", "r", stdin);
    #endif
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    //clock_t clk = clock();
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        p[i] = i;
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a + 1, a + n + 1);
    for(int i = 2; i <= n; i++) {
        edgeList.pb(II(a[i].first + a[1].first, ii(a[i].second, a[1].second)));
        //cout << a[i].first + a[1].first << " " << a[i].second << " " << a[1].second << endl;
    }
    for(int i = 1; i <= m; i++) {
        int u, v;
        ll w;
        cin >> u >> v >> w;
        //cout << w << " " << u << " " << v << endl;
        edgeList.pb(II(w,ii(u,v)));
    }
    sort(edgeList.begin(), edgeList.end());
    for(int i = 0; i < edgeList.size(); i++) {
        int u = edgeList[i].second.first;
        int v = edgeList[i].second.second;
        ll w = edgeList[i].first;
        if(!isSameSet(u,v)) {
            mergeSet(u,v);
            ans += 1LL*w;
        }
    }
    cout << ans << endl;
    //cerr << "Time (in ms): " << double(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';
    return 0;
}