#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define fi first
#define se second
#define p_b push_back
#define pll pair<ll,ll>
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define ld long double
#define sset ordered_set

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
const ll MAXN = 1123456;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename T>
T sqr(T x){
    return x * x;
}

template <typename T>
void vout(T s){
    cout << s << endl;
    exit(0);
}

ll bp(ll a,ll n){
    ll res = 1;
    while(n){
        if(n % 2)res *= a;
        a *= a;
        n >>= 1;
    }
    return res;
}

vector <pll> v[MAXN];

ll p[MAXN], kol[MAXN], mn[MAXN];

ll get(ll x){
    if(p[x] != x)p[x] = get(p[x]);
    return p[x];
}

int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ll n, m;

    cin >> n >> m;

    vector <ll> a(n + 1);
    vector <pll> c(n + 1);

    set <pll> mb;

    for(int i = 1; i <= n; i++){
        cin >> a[i];
        mn[i] = a[i];
        mb.insert({a[i], i});
        p[i] = i;
        c[i].fi = a[i];
        c[i].se = i;
    }

    sort(c.begin() + 1, c.end());

    ll val, to;

    val = c[1].fi, to = c[1].se;

    vector <pair <ll, pll> > b(m);

    for(int i = 0; i < m; i++){
        cin >> b[i].se.fi >> b[i].se.se >> b[i].fi;
    }

    sort(all(b));

    ll uk = 0;
    ll ans = 0;

    while(uk < m){
        ll ra = get(b[uk].se.fi), rb = get(b[uk].se.se);
        if(ra == rb){
            uk++;
            continue;
        }
        ll value = b[uk].fi;
        mb.erase({mn[ra], ra});

        pll xe = *mb.begin();
        if(mn[ra] + xe.fi < value){
            ans += mn[ra] + xe.fi;
            mn[ra] = min(mn[ra], mn[rb]);
            p[get(xe.se)] = ra;
            mb.erase(mb.begin());
            mb.insert({mn[ra], ra});
        }else{
            ans += value;
            mb.erase({mn[rb], rb});
            mn[ra] = min(mn[ra], mn[rb]);
            p[rb] = ra;
            mb.insert({mn[ra], ra});
        }

    }

    ll kol = 0;

    for(int i = 1; i <= n; i++)if(get(c[i].se) != get(to) && get(c[i].se) == c[i].se){
        ans += c[i].fi + val;
    }

    cout << ans << "\n";

    cerr << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl;
    return 0;
}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define fi first
#define se second
#define p_b push_back
#define pll pair<ll,ll>
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define ld long double
#define sset ordered_set

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
const ll MAXN = 1123456;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename T>
T sqr(T x){
    return x * x;
}

template <typename T>
void vout(T s){
    cout << s << endl;
    exit(0);
}

ll bp(ll a,ll n){
    ll res = 1;
    while(n){
        if(n % 2)res *= a;
        a *= a;
        n >>= 1;
    }
    return res;
}

vector <pll> v[MAXN];

ll p[MAXN], kol[MAXN], mn[MAXN];

ll get(ll x){
    if(p[x] != x)p[x] = get(p[x]);
    return p[x];
}

int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ll n, m;

    cin >> n >> m;

    vector <ll> a(n + 1);
    vector <pll> c(n + 1);

    set <pll> mb;

    for(int i = 1; i <= n; i++){
        cin >> a[i];
        mn[i] = a[i];
        mb.insert({a[i], i});
        p[i] = i;
        c[i].fi = a[i];
        c[i].se = i;
    }

    sort(c.begin() + 1, c.end());

    ll val, to;

    val = c[1].fi, to = c[1].se;

    vector <pair <ll, pll> > b(m);

    for(int i = 0; i < m; i++){
        cin >> b[i].se.fi >> b[i].se.se >> b[i].fi;
    }

    for(int i = 2; i <= n; i++)b.p_b({c[i].fi + val, {c[i].se, to}});

    sort(all(b));

    ll ans = 0;

    for(int i = 0; i < b.size(); i++){
        ll ra = get(b[i].se.fi), rb = get(b[i].se.se), val = b[i].fi;
        if(ra != rb){
            ans += val;
            p[ra] = rb;
        }
    }

    cout << ans << "\n";

    cerr << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl;
    return 0;
}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define fi first
#define se second
#define p_b push_back
#define pll pair<ll,ll>
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define ld long double
#define sset ordered_set

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
const ll MAXN = 1123456;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename T>
T sqr(T x){
    return x * x;
}

template <typename T>
void vout(T s){
    cout << s << endl;
    exit(0);
}

ll bp(ll a,ll n){
    ll res = 1;
    while(n){
        if(n % 2)res *= a;
        a *= a;
        n >>= 1;
    }
    return res;
}

vector <pll> v[MAXN];

ll p[MAXN], kol[MAXN], mn[MAXN];

ll get(ll x){
    if(p[x] != x)p[x] = get(p[x]);
    return p[x];
}

int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ll n, m;

    cin >> n >> m;

    vector <ll> a(n + 1);
    vector <pll> c(n + 1);

    set <pll> mb;

    for(int i = 1; i <= n; i++){
        cin >> a[i];
        mn[i] = a[i];
        mb.insert({a[i], i});
        p[i] = i;
        c[i].fi = a[i];
        c[i].se = i;
    }

    sort(c.begin() + 1, c.end());

    ll val, to;

    val = c[1].fi, to = c[1].se;

    vector <pair <ll, pll> > b(m);

    for(int i = 0; i < m; i++){
        cin >> b[i].se.fi >> b[i].se.se >> b[i].fi;
    }

    sort(all(b));

    ll uk = 0;
    ll ans = 0;

    while(uk < m){
        ll ra = get(b[uk].se.fi), rb = get(b[uk].se.se);
        if(ra == rb){
            uk++;
            continue;
        }
        ll value = b[uk].fi;
        mb.erase({mn[ra], ra});

        pll xe = *mb.begin();
        if(mn[ra] + xe.fi < value){
            ans += mn[ra] + xe.fi;
            mn[ra] = min(mn[ra], mn[rb]);
            p[get(xe.se)] = ra;
            mb.erase(mb.begin());
            mb.insert({mn[ra], ra});
        }else{
            ans += value;
            mb.erase({mn[rb], rb});
            mn[ra] = min(mn[ra], mn[rb]);
            p[rb] = ra;
            mb.insert({mn[ra], ra});
        }

    }

    for(int i = 1; i <= n; i++)if(get(c[i].se) != get(to)){
        ans += c[i].fi + val;
    }

    cout << ans << "\n";

    cerr << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl;
    return 0;
}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define fi first
#define se second
#define p_b push_back
#define pll pair<ll,ll>
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define ld long double
#define sset ordered_set

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
const ll MAXN = 1123456;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename T>
T sqr(T x){
    return x * x;
}

template <typename T>
void vout(T s){
    cout << s << endl;
    exit(0);
}

ll bp(ll a,ll n){
    ll res = 1;
    while(n){
        if(n % 2)res *= a;
        a *= a;
        n >>= 1;
    }
    return res;
}

vector <pll> v[MAXN];

ll p[MAXN], kol[MAXN], mn[MAXN];

ll get(ll x){
    if(p[x] != x)p[x] = get(p[x]);
    return p[x];
}

int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ll n, m;

    cin >> n >> m;

    vector <ll> a(n + 1);
    vector <pll> c(n + 1);

    set <pll> mb;

    for(int i = 1; i <= n; i++){
        cin >> a[i];
        mn[i] = a[i];
        mb.insert({a[i], i});
        p[i] = i;
        c[i].fi = a[i];
        c[i].se = i;
    }

    sort(c.begin() + 1, c.end());

    ll val, to;

    val = c[1].fi, to = c[1].se;

    vector <pair <ll, pll> > b(m);

    for(int i = 0; i < m; i++){
        cin >> b[i].se.fi >> b[i].se.se >> b[i].fi;
    }

    sort(all(b));

    ll uk = 0;
    ll ans = 0;

    while(uk < m){
        ll ra = get(b[uk].se.fi), rb = get(b[uk].se.se);
        if(ra == rb){
            uk++;
            continue;
        }
        ll value = b[uk].fi;
        mb.erase({mn[ra], ra});

        pll xe = *mb.begin();
        if(mn[ra] + xe.fi < value){
            ans += mn[ra] + xe.fi;
            mn[ra] = min(mn[ra], mn[xe.se]);
            p[get(xe.se)] = ra;
            mb.erase(mb.begin());
            mb.insert({mn[ra], ra});
        }else{
            mb.insert({mn[ra], ra});
            mb.erase({mn[rb], rb});
            xe = *mb.begin();
            if(mn[rb] + xe.fi < value){
                ans += mn[rb] + xe.fi;
                mn[rb] = min(mn[rb], mn[xe.se]);
                p[get(xe.se)] = rb;
                mb.erase(mb.begin());
                mb.insert({mn[rb], rb});
            }else{
                ans += value;
                mb.erase({mn[ra], ra});
                mn[ra] = min(mn[ra], mn[rb]);
                p[rb] = ra;
                mb.insert({mn[ra], ra});
            }
        }

    }

    ll kol = 0;

    for(int i = 1; i <= n; i++)if(get(c[i].se) != get(to) && get(c[i].se) == c[i].se){
        ans += c[i].fi + val;
    }

    cout << ans << "\n";

    cerr << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl;
    return 0;
}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define fi first
#define se second
#define p_b push_back
#define pll pair<ll,ll>
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define ld long double
#define sset ordered_set

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
const ll MAXN = 1123456;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename T>
T sqr(T x){
    return x * x;
}

template <typename T>
void vout(T s){
    cout << s << endl;
    exit(0);
}

ll bp(ll a,ll n){
    ll res = 1;
    while(n){
        if(n % 2)res *= a;
        a *= a;
        n >>= 1;
    }
    return res;
}

ll p[MAXN], kol[MAXN];

set <ll> v[MAXN];

ll get(ll x){
    if(p[x] != x)p[x] = get(p[x]);
    return p[x];
}

int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ll n, m;

    cin >> n >> m;

    vector <ll> a(n + 1);

    for(int i = 1; i <= n; i++){
        cin >> a[i];
        p[i] = i;
        v[i].insert(a[i]);
        kol[i] = 1;
    }

    vector < pair <pll,ll> > b(m);

    for(int i = 0; i < m; i++)cin >> b[i].fi.fi >> b[i].fi.se >> b[i].se;

    set <pll> s;

    for(int i = 1; i <= n; i++)s.insert({1ll, i});

    ll ans = 0;

    while(s.size() > 1){
        pll xe = *s.begin();
        ll x = xe.se, val = 1e18, to = 0, mn = *v[x].begin();

        for(int i = 1; i <= n; i++)if(get(i) == i && i != x){
            ll ra = mn + (*v[i].begin());
            if(ra < val){
                val = ra;
                to = i;
            }
        }

        for(int i = 0; i < m; i++){
            ll ra = get(b[i].fi.fi), rb = get(b[i].fi.se), value = b[i].se;
            if(ra != rb && ra == x){
                if(val > value){
                    val = value;
                    to = rb;
                }
            }
            if(ra != rb && rb == x){
                if(val > value){
                    val = value;
                    to = ra;
                }
            }
        }

        s.erase({kol[x], x});
        s.erase({kol[to], to});
        kol[x] += kol[to];

        p[to] = x;

        for(auto i : v[to])v[x].insert(i);
        v[to].clear();
        s.insert({kol[x], x});

        ans += val;

    }

    cout << ans << "\n";

    cerr << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl;
    return 0;
}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define fi first
#define se second
#define p_b push_back
#define pll pair<ll,ll>
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define ld long double
#define sset ordered_set

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
const ll MAXN = 1123456;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename T>
T sqr(T x){
    return x * x;
}

template <typename T>
void vout(T s){
    cout << s << endl;
    exit(0);
}

ll bp(ll a,ll n){
    ll res = 1;
    while(n){
        if(n % 2)res *= a;
        a *= a;
        n >>= 1;
    }
    return res;
}

vector <ll> v[MAXN];

ll p[MAXN], kol[MAXN], mn[MAXN];

ll get(ll x){
    if(p[x] != x)p[x] = get(p[x]);
    return p[x];
}

int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ll n, m;

    cin >> n >> m;

    vector <ll> a(n + 1);
    vector <pll> c(n + 1);

    for(int i = 1; i <= n; i++){
        cin >> a[i];
        p[i] = i;
        c[i].fi = a[i];
        c[i].se = i;
        mn[i] = a[i];
    }

    vector < pair <ll,pll> > b;

    sort(c.begin() + 1, c.end());

    ll val, to;

    val = c[1].fi, to = c[1].se;

    for(int i = 0; i < m; i++){
        ll aa, x, c;
        cin >> aa >> x >> c;
        b.p_b({c, {aa, x}});
    }

    ll ans = 0;
    if(!b.empty()){
        sort(all(b));

        for(auto i : b){
            ll ra = get(i.se.fi), rb = get(i.se.se);
            ll sc = 2 * val + mn[ra] + mn[rb];

            if(get(to) == ra)sc -= val + mn[ra];
            if(get(to) == rb)sc -= val + mn[rb];

            if(ra == get(to)){
                if(ra != rb){
                    ans += min(i.fi, mn[ra] + mn[rb]);
                    p[ra] = rb;
                    mn[rb] = min(mn[ra], mn[rb]);
                    mn[ra] = min(mn[ra], mn[rb]);
                }
            }else if(rb == get(to)){
                if(ra != rb){
                    ans += min(i.fi, mn[ra] + mn[rb]);
                    p[ra] = rb;
                    mn[rb] = min(mn[ra], mn[rb]);
                    mn[ra] = min(mn[ra], mn[rb]);
                }
            }else{

                if(ra != rb && min(i.fi, mn[ra] + mn[rb]) + val < sc){
                    ans += min(i.fi, mn[ra] + mn[rb]);
                    p[ra] = rb;
                    mn[rb] = min(mn[ra], mn[rb]);
                    mn[ra] = min(mn[ra], mn[rb]);
                }

            }

        }
    }

    for(int i = 1; i <= n; i++)if(get(c[i].se) != get(to)){
        p[get(c[i].se)] = get(to);
        ans += val + c[i].fi;
    }

    cout << ans << "\n";

    cerr << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl;
    return 0;
}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define fi first
#define se second
#define p_b push_back
#define pll pair<ll,ll>
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define ld long double
#define sset ordered_set

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
const ll MAXN = 1123456;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename T>
T sqr(T x){
    return x * x;
}

template <typename T>
void vout(T s){
    cout << s << endl;
    exit(0);
}

ll bp(ll a,ll n){
    ll res = 1;
    while(n){
        if(n % 2)res *= a;
        a *= a;
        n >>= 1;
    }
    return res;
}

vector <ll> v[MAXN];

ll p[MAXN], kol[MAXN], mn[MAXN];

ll get(ll x){
    if(p[x] != x)p[x] = get(p[x]);
    return p[x];
}

int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ll n, m;

    cin >> n >> m;

    vector <ll> a(n + 1);
    vector <pll> c(n + 1);

    for(int i = 1; i <= n; i++){
        cin >> a[i];
        p[i] = i;
        c[i].fi = a[i];
        c[i].se = i;
        mn[i] = a[i];
    }

    vector < pair <ll,pll> > b;

    sort(c.begin() + 1, c.end());

    ll val, to;

    val = c[1].fi, to = c[1].se;

    for(int i = 0; i < m; i++){
        ll aa, x, c;
        cin >> aa >> x >> c;
        b.p_b({c, {aa, x}});
    }

    ll ans = 0;
    if(!b.empty()){
        sort(all(b));

        for(auto i : b){
            ll ra = get(i.se.fi), rb = get(i.se.se);
            ll sc = 2 * val + mn[ra] + mn[rb];

            if(get(to) == ra)sc -= val + mn[ra];
            if(get(to) == rb)sc -= val + mn[rb];

            if(ra != rb && i.fi < sc){
                ans += i.fi;
                p[ra] = rb;
                mn[rb] = min(mn[ra], mn[rb]);
            }
        }
    }

    for(int i = 1; i <= n; i++)if(get(c[i].se) != get(to)){
        p[get(c[i].se)] = get(to);
        ans += val + c[i].fi;
    }

    cout << ans << "\n";

    cerr << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#define endl '\n'

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pi;
typedef pair<pi, ll> ppi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<vpi> vvpi;
typedef vector<ppi> vppi;
typedef vector<bool> vb;
typedef map<ll, ll> mii;
typedef set<pi> spi;
typedef set<ll> si;
typedef vector<si> vsi;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using Mi = map<ll, T>;
template <typename T> using MMi = map<ll, Mi<T>>;

/*
int main() {
	printTest();
	return 0;
}
*/
//ios::sync_with_stdio(false);
//cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
vi tree;

void build(vi &arr, ll ind, ll l, ll r) {
	if (l == r) {
		tree[ind] = arr[l];
		return;
	}
	ll mid = (l + r) / 2;
	build(arr, ind * 2, l, mid);
	build(arr, ind * 2 + 1, mid + 1, r);
	tree[ind] = max(tree[ind * 2], tree[ind * 2 + 1]);
}
ll getMax(ll ind, ll tl, ll tr, ll l, ll r) {
	if (l > r)
		return 0;
	if (l == tl && r == tr)
		return tree[ind];
	ll tm = (tl + tr) / 2;
	ll a = getMax(ind * 2, tl, tm, l, min(r, tm));
	ll b = getMax(ind * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
	return max(a, b);
}

vb prim;
void er() {
	ll n = 1e6;
	prim = vb(n + 1, true);
	prim[0] = prim[1] = false;
	for (ll i = 2; i <= n; i++) {
		if (prim[i]) {
			for (ll j = i * i; j <= n; j += i) {
				prim[j] = false;
			}
		}
	}
}
vi topSort(ll v, V<si> &g) {
	vi ans;
	vb viz(g.size(),false);
	//dfs(v, g, viz, ans);
	return ans;
}
ll rast(pi &a, pi &b) {
	return abs(a.first - b.first) + abs(a.second - b.second);
}
vi z_function(string &s) {
	ll n = s.length();
	vi z(n,0);
	ll l = 0, r = 0;
	for (ll i = 1; i < n; i++) {
		if (i <= r) {
			z[i] = min(r - i + 1, z[i - l]);
		}
		while (i+z[i]<n && s[z[i]] == s[z[i]+i]) {
			z[i]++;
		}
		if (i + z[i] - 1 > r) {
			l = i;
			r = i + z[i] - 1;
		}
	}
	return z;
}
bool comp(const string &a, const string &b) {
	return a.size() < b.size();
}

void printTest() {
	freopen("output.txt", "w", stdout);
	cout << "1000 500 1000" << endl;
	for (int i = 0; i < 500; i++) {
		cout << i*2 << " " << i*2 + 1 << endl;
	}
	for (int i = 0; i < 1000; i++) {
		cout << i << " " << 1000 - i << endl;
	}
}

ll getDiam(ll v, vvi &g, vb &viz, vi &ans) {
	viz[v] = true;
	multiset<pi> m;
	ll ret = 0;
	for (ll u : g[v]) {
		if (!viz[u]) {
			ll glub = getDiam(u, g, viz, ans)+1;
			ret = max(ret, glub);
			m.insert({ glub,u });
			if (m.size() > 2) {
				m.erase(m.begin());
			}

		}
	}
	ll diam = 0;
	for (pi a : m) {
		diam += a.first;
	}
	ans[v] = diam;
	return ret;
}
void createVertx(ll v, vsi &g, vb &viz, vi &vertx) {
	vertx.push_back(v);
	viz[v] = true;
	for (ll u : g[v]) {
		if (!viz[u]) {
			createVertx(u, g, viz, vertx);
		}
	}
}
void centry(vi &vertx, vsi g, pi &ans, vi &count) {

	spi lists;
	for (ll v : vertx) {
		lists.insert({ count[v],v });
	}

	ll rad = 0;
	while (lists.size() > 2) {
		rad++;
		si del;
		while (lists.begin()->first==1) {
			del.insert(lists.begin()->second);
			lists.erase(lists.begin());
		}
		for (ll v : del) {
			ll u = *g[v].begin();
			pi p;
			p.first = count[u];
			p.second = u;
			lists.erase(p);
			count[u]--;
			g[u].erase(v);
			lists.insert({ count[u],u });
		}
	}
	ans.first = lists.begin()->second;
	if (lists.size() == 2) {
		rad++;
	}
	ans.second = rad;
}

pi getCentry(ll v, vsi &g, vb &viz, vi &count) {
	vi vertx;
	createVertx(v, g, viz, vertx);
	pi ans;
	centry(vertx, g, ans, count);
	return { ans.second, ans.first };
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n, m;
	cin >> n >> m;
	vi a(n);
	ll core = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] < a[core]) {
			core = i;
		}
	}
	vvpi matr(n, vpi());
	for (int i = 0; i < m; i++) {
		ll x, y, c;
		cin >> x >> y >> c;
		x--; y--;
		matr[x].push_back({ y,c });
		matr[y].push_back({ x,c });
	}
	vi parent(n);
	for (int i = 0; i < n; i++) {
		parent[i] = i;
	}
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		if (i == core) {
			continue;
		}
		ll soed = (a[i] + a[core]);
		pi minC = {core,soed};
		for (pi p : matr[i]) {
			ll v = p.first;
			ll c = p.second;
			if (c < minC.second) {
				minC.second = c;
				minC.first = v;
			}
		}
		if (minC.second!=soed) {
			if (minC.first == core) {
				sum += minC.second;
				continue;
			}
			ll v = parent[minC.first];
			if (a[v] < a[i]) {
				parent[i] = v;
				sum += minC.second;
				continue;
			}
		}
		sum += soed;
	}
	cout << sum;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#define endl '\n'

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pi;
typedef pair<pi, ll> ppi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<vpi> vvpi;
typedef vector<ppi> vppi;
typedef vector<bool> vb;
typedef map<ll, ll> mii;
typedef set<pi> spi;
typedef set<ll> si;
typedef vector<si> vsi;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using Mi = map<ll, T>;
template <typename T> using MMi = map<ll, Mi<T>>;

/*
int main() {
	printTest();
	return 0;
}
*/
//ios::sync_with_stdio(false);
//cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
vi tree;

void build(vi &arr, ll ind, ll l, ll r) {
	if (l == r) {
		tree[ind] = arr[l];
		return;
	}
	ll mid = (l + r) / 2;
	build(arr, ind * 2, l, mid);
	build(arr, ind * 2 + 1, mid + 1, r);
	tree[ind] = max(tree[ind * 2], tree[ind * 2 + 1]);
}
ll getMax(ll ind, ll tl, ll tr, ll l, ll r) {
	if (l > r)
		return 0;
	if (l == tl && r == tr)
		return tree[ind];
	ll tm = (tl + tr) / 2;
	ll a = getMax(ind * 2, tl, tm, l, min(r, tm));
	ll b = getMax(ind * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
	return max(a, b);
}

vb prim;
void er() {
	ll n = 1e6;
	prim = vb(n + 1, true);
	prim[0] = prim[1] = false;
	for (ll i = 2; i <= n; i++) {
		if (prim[i]) {
			for (ll j = i * i; j <= n; j += i) {
				prim[j] = false;
			}
		}
	}
}
vi topSort(ll v, V<si> &g) {
	vi ans;
	vb viz(g.size(),false);
	//dfs(v, g, viz, ans);
	return ans;
}
ll rast(pi &a, pi &b) {
	return abs(a.first - b.first) + abs(a.second - b.second);
}
vi z_function(string &s) {
	ll n = s.length();
	vi z(n,0);
	ll l = 0, r = 0;
	for (ll i = 1; i < n; i++) {
		if (i <= r) {
			z[i] = min(r - i + 1, z[i - l]);
		}
		while (i+z[i]<n && s[z[i]] == s[z[i]+i]) {
			z[i]++;
		}
		if (i + z[i] - 1 > r) {
			l = i;
			r = i + z[i] - 1;
		}
	}
	return z;
}
bool comp(const string &a, const string &b) {
	return a.size() < b.size();
}

void printTest() {
	freopen("output.txt", "w", stdout);
	cout << "1000 500 1000" << endl;
	for (int i = 0; i < 500; i++) {
		cout << i*2 << " " << i*2 + 1 << endl;
	}
	for (int i = 0; i < 1000; i++) {
		cout << i << " " << 1000 - i << endl;
	}
}

ll getDiam(ll v, vvi &g, vb &viz, vi &ans) {
	viz[v] = true;
	multiset<pi> m;
	ll ret = 0;
	for (ll u : g[v]) {
		if (!viz[u]) {
			ll glub = getDiam(u, g, viz, ans)+1;
			ret = max(ret, glub);
			m.insert({ glub,u });
			if (m.size() > 2) {
				m.erase(m.begin());
			}

		}
	}
	ll diam = 0;
	for (pi a : m) {
		diam += a.first;
	}
	ans[v] = diam;
	return ret;
}
void createVertx(ll v, vsi &g, vb &viz, vi &vertx) {
	vertx.push_back(v);
viz[v] = true;
for (ll u : g[v]) {
	if (!viz[u]) {
		createVertx(u, g, viz, vertx);
	}
}
}
void centry(vi &vertx, vsi g, pi &ans, vi &count) {

	spi lists;
	for (ll v : vertx) {
		lists.insert({ count[v],v });
	}

	ll rad = 0;
	while (lists.size() > 2) {
		rad++;
		si del;
		while (lists.begin()->first == 1) {
			del.insert(lists.begin()->second);
			lists.erase(lists.begin());
		}
		for (ll v : del) {
			ll u = *g[v].begin();
			pi p;
			p.first = count[u];
			p.second = u;
			lists.erase(p);
			count[u]--;
			g[u].erase(v);
			lists.insert({ count[u],u });
		}
	}
	ans.first = lists.begin()->second;
	if (lists.size() == 2) {
		rad++;
	}
	ans.second = rad;
}

pi getCentry(ll v, vsi &g, vb &viz, vi &count) {
	vi vertx;
	createVertx(v, g, viz, vertx);
	pi ans;
	centry(vertx, g, ans, count);
	return { ans.second, ans.first };
}

vi parent;
vi rang;

void make_set(int v) {
	parent[v] = v;
	rang[v] = 0;
}

int find_set(int v) {
	if (v == parent[v])
		return v;
	return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
	a = find_set(a);
	b = find_set(b);
	if (a != b) {
		parent[b] = a;
	}
}

map<pi, ll> path;
vi a;
ll getPath(ll v, ll u) {
	if (path.find({ u,v }) == path.end()) {
		return a[v] + a[u];
	}
	return min(a[v] + a[u], path[{u, v}]);
}

void obed() {

}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//freopen("output.txt", "r", stdin);
	ll n, m;
	cin >> n >> m;
	a = vi(n);
	ll core = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] < a[core]) {
			core = i;
		}
	}
	vvi matr(n, vi());
	for (int i = 0; i < m; i++) {
		ll x, y, c;
		cin >> x >> y >> c;
		x--; y--;
		if ((path.find({ x,y }) == path.end() && c<a[x]+a[y]) || (path.find({ x,y }) != path.end() && path[{x, y}] > c)){
			matr[x].push_back(y);
			matr[y].push_back(x);
			path[{y, x}] = c;
			path[{x, y}] = c;
		}
	}
	parent = vi(n);
	rang = vi(n);
	for (int i = 0; i < n; i++) {
		make_set(i);
	}
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		if (i == core) {
			continue;
		}
		for (ll v : matr[i]) {
			if (v == core) {
				continue;
			}
			ll path2 = getPath(core, find_set(i));
			ll c = getPath(i, v);
			if (c < path2) {
				ll vv = find_set(v);
				if (vv == i) {
					continue;
				}
				ll p1 = getPath(core, vv);
				if (p1 < path2) {
					union_sets(vv, i);
					sum += c;
				}
			}
		}
	}

	for (int i = 0; i < n; i++) {
		if (i == core) {
			continue;
		}
		if (parent[i] == i) {
			sum += getPath(core, i);
		}
	}
	cout << sum;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#define endl '\n'

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pi;
typedef pair<pi, ll> ppi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<vpi> vvpi;
typedef vector<ppi> vppi;
typedef vector<bool> vb;
typedef map<ll, ll> mii;
typedef set<pi> spi;
typedef set<ll> si;
typedef vector<si> vsi;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using Mi = map<ll, T>;
template <typename T> using MMi = map<ll, Mi<T>>;

/*
int main() {
	printTest();
	return 0;
}
*/
//ios::sync_with_stdio(false);
//cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
vi tree;

void build(vi &arr, ll ind, ll l, ll r) {
	if (l == r) {
		tree[ind] = arr[l];
		return;
	}
	ll mid = (l + r) / 2;
	build(arr, ind * 2, l, mid);
	build(arr, ind * 2 + 1, mid + 1, r);
	tree[ind] = max(tree[ind * 2], tree[ind * 2 + 1]);
}
ll getMax(ll ind, ll tl, ll tr, ll l, ll r) {
	if (l > r)
		return 0;
	if (l == tl && r == tr)
		return tree[ind];
	ll tm = (tl + tr) / 2;
	ll a = getMax(ind * 2, tl, tm, l, min(r, tm));
	ll b = getMax(ind * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
	return max(a, b);
}

vb prim;
void er() {
	ll n = 1e6;
	prim = vb(n + 1, true);
	prim[0] = prim[1] = false;
	for (ll i = 2; i <= n; i++) {
		if (prim[i]) {
			for (ll j = i * i; j <= n; j += i) {
				prim[j] = false;
			}
		}
	}
}
vi topSort(ll v, V<si> &g) {
	vi ans;
	vb viz(g.size(),false);
	//dfs(v, g, viz, ans);
	return ans;
}
ll rast(pi &a, pi &b) {
	return abs(a.first - b.first) + abs(a.second - b.second);
}
vi z_function(string &s) {
	ll n = s.length();
	vi z(n,0);
	ll l = 0, r = 0;
	for (ll i = 1; i < n; i++) {
		if (i <= r) {
			z[i] = min(r - i + 1, z[i - l]);
		}
		while (i+z[i]<n && s[z[i]] == s[z[i]+i]) {
			z[i]++;
		}
		if (i + z[i] - 1 > r) {
			l = i;
			r = i + z[i] - 1;
		}
	}
	return z;
}
bool comp(const string &a, const string &b) {
	return a.size() < b.size();
}

void printTest() {
	freopen("output.txt", "w", stdout);
	cout << "1000 500 1000" << endl;
	for (int i = 0; i < 500; i++) {
		cout << i*2 << " " << i*2 + 1 << endl;
	}
	for (int i = 0; i < 1000; i++) {
		cout << i << " " << 1000 - i << endl;
	}
}

ll getDiam(ll v, vvi &g, vb &viz, vi &ans) {
	viz[v] = true;
	multiset<pi> m;
	ll ret = 0;
	for (ll u : g[v]) {
		if (!viz[u]) {
			ll glub = getDiam(u, g, viz, ans)+1;
			ret = max(ret, glub);
			m.insert({ glub,u });
			if (m.size() > 2) {
				m.erase(m.begin());
			}

		}
	}
	ll diam = 0;
	for (pi a : m) {
		diam += a.first;
	}
	ans[v] = diam;
	return ret;
}
void createVertx(ll v, vsi &g, vb &viz, vi &vertx) {
	vertx.push_back(v);
viz[v] = true;
for (ll u : g[v]) {
	if (!viz[u]) {
		createVertx(u, g, viz, vertx);
	}
}
}
void centry(vi &vertx, vsi g, pi &ans, vi &count) {

	spi lists;
	for (ll v : vertx) {
		lists.insert({ count[v],v });
	}

	ll rad = 0;
	while (lists.size() > 2) {
		rad++;
		si del;
		while (lists.begin()->first == 1) {
			del.insert(lists.begin()->second);
			lists.erase(lists.begin());
		}
		for (ll v : del) {
			ll u = *g[v].begin();
			pi p;
			p.first = count[u];
			p.second = u;
			lists.erase(p);
			count[u]--;
			g[u].erase(v);
			lists.insert({ count[u],u });
		}
	}
	ans.first = lists.begin()->second;
	if (lists.size() == 2) {
		rad++;
	}
	ans.second = rad;
}

pi getCentry(ll v, vsi &g, vb &viz, vi &count) {
	vi vertx;
	createVertx(v, g, viz, vertx);
	pi ans;
	centry(vertx, g, ans, count);
	return { ans.second, ans.first };
}

vi parent;
vi rang;

void make_set(int v) {
	parent[v] = v;
	rang[v] = 0;
}

int find_set(int v) {
	if (v == parent[v])
		return v;
	return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
	a = find_set(a);
	b = find_set(b);
	if (a != b) {
		parent[b] = a;
	}
}

map<pi, ll> path;
vi a;
ll getPath(ll v, ll u) {
	if (path.find({ u,v }) == path.end()) {
		return a[v] + a[u];
	}
	return min(a[v] + a[u], path[{u, v}]);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//freopen("output.txt", "r", stdin);
	ll n, m;
	cin >> n >> m;
	a = vi(n);
	ll core = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] < a[core]) {
			core = i;
		}
	}
	vvi matr(n, vi());
	for (int i = 0; i < m; i++) {
		ll x, y, c;
		cin >> x >> y >> c;
		x--; y--;
		if ((path.find({ x,y }) == path.end() && c<a[x]+a[y]) || (path.find({ x,y }) != path.end() && path[{x, y}] > c)){
			matr[x].push_back(y);
			matr[y].push_back(x);
			path[{y, x}] = c;
			path[{x, y}] = c;
		}
	}
	parent = vi(n);
	rang = vi(n);
	for (int i = 0; i < n; i++) {
		make_set(i);
	}
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		if (i == core) {
			continue;
		}
		if (i != find_set(i)) {
			continue;
		}
		ll path2 = getPath(core, i);
		pi minC = {core,path2};
		for (ll v : matr[i]) {
			if (v == core) {
				continue;
			}
			ll c = getPath(i, v);
			if (c < minC.second) {
				minC.second = c;
				minC.first = v;
			}
		}

		if (minC.first!=core) {
			ll v = find_set(minC.first);
			if (v == i) {
				continue;
			}
			ll p1 = getPath(core, v);
			ll p2 = getPath(core, i);
			if (p1 < p2 ){
				union_sets(v, i);
			}
			else {
				union_sets(i, v);
			}
			sum += minC.second;
		}
	}

	for (int i = 0; i < n; i++) {
		if (i == core) {
			continue;
		}
		if (parent[i] == i) {
			sum += getPath(core, i);
		}
	}
	cout << sum;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#define endl '\n'

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pi;
typedef pair<pi, ll> ppi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<vpi> vvpi;
typedef vector<ppi> vppi;
typedef vector<bool> vb;
typedef map<ll, ll> mii;
typedef set<pi> spi;
typedef set<ll> si;
typedef vector<si> vsi;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using Mi = map<ll, T>;
template <typename T> using MMi = map<ll, Mi<T>>;

/*
int main() {
	printTest();
	return 0;
}
*/
//ios::sync_with_stdio(false);
//cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
vi tree;

void build(vi &arr, ll ind, ll l, ll r) {
	if (l == r) {
		tree[ind] = arr[l];
		return;
	}
	ll mid = (l + r) / 2;
	build(arr, ind * 2, l, mid);
	build(arr, ind * 2 + 1, mid + 1, r);
	tree[ind] = max(tree[ind * 2], tree[ind * 2 + 1]);
}
ll getMax(ll ind, ll tl, ll tr, ll l, ll r) {
	if (l > r)
		return 0;
	if (l == tl && r == tr)
		return tree[ind];
	ll tm = (tl + tr) / 2;
	ll a = getMax(ind * 2, tl, tm, l, min(r, tm));
	ll b = getMax(ind * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
	return max(a, b);
}

vb prim;
void er() {
	ll n = 1e6;
	prim = vb(n + 1, true);
	prim[0] = prim[1] = false;
	for (ll i = 2; i <= n; i++) {
		if (prim[i]) {
			for (ll j = i * i; j <= n; j += i) {
				prim[j] = false;
			}
		}
	}
}
vi topSort(ll v, V<si> &g) {
	vi ans;
	vb viz(g.size(),false);
	//dfs(v, g, viz, ans);
	return ans;
}
ll rast(pi &a, pi &b) {
	return abs(a.first - b.first) + abs(a.second - b.second);
}
vi z_function(string &s) {
	ll n = s.length();
	vi z(n,0);
	ll l = 0, r = 0;
	for (ll i = 1; i < n; i++) {
		if (i <= r) {
			z[i] = min(r - i + 1, z[i - l]);
		}
		while (i+z[i]<n && s[z[i]] == s[z[i]+i]) {
			z[i]++;
		}
		if (i + z[i] - 1 > r) {
			l = i;
			r = i + z[i] - 1;
		}
	}
	return z;
}
bool comp(const string &a, const string &b) {
	return a.size() < b.size();
}

void printTest() {
	freopen("output.txt", "w", stdout);
	cout << "1000 500 1000" << endl;
	for (int i = 0; i < 500; i++) {
		cout << i*2 << " " << i*2 + 1 << endl;
	}
	for (int i = 0; i < 1000; i++) {
		cout << i << " " << 1000 - i << endl;
	}
}

ll getDiam(ll v, vvi &g, vb &viz, vi &ans) {
	viz[v] = true;
	multiset<pi> m;
	ll ret = 0;
	for (ll u : g[v]) {
		if (!viz[u]) {
			ll glub = getDiam(u, g, viz, ans)+1;
			ret = max(ret, glub);
			m.insert({ glub,u });
			if (m.size() > 2) {
				m.erase(m.begin());
			}

		}
	}
	ll diam = 0;
	for (pi a : m) {
		diam += a.first;
	}
	ans[v] = diam;
	return ret;
}
void createVertx(ll v, vsi &g, vb &viz, vi &vertx) {
	vertx.push_back(v);
viz[v] = true;
for (ll u : g[v]) {
	if (!viz[u]) {
		createVertx(u, g, viz, vertx);
	}
}
}
void centry(vi &vertx, vsi g, pi &ans, vi &count) {

	spi lists;
	for (ll v : vertx) {
		lists.insert({ count[v],v });
	}

	ll rad = 0;
	while (lists.size() > 2) {
		rad++;
		si del;
		while (lists.begin()->first == 1) {
			del.insert(lists.begin()->second);
			lists.erase(lists.begin());
		}
		for (ll v : del) {
			ll u = *g[v].begin();
			pi p;
			p.first = count[u];
			p.second = u;
			lists.erase(p);
			count[u]--;
			g[u].erase(v);
			lists.insert({ count[u],u });
		}
	}
	ans.first = lists.begin()->second;
	if (lists.size() == 2) {
		rad++;
	}
	ans.second = rad;
}

pi getCentry(ll v, vsi &g, vb &viz, vi &count) {
	vi vertx;
	createVertx(v, g, viz, vertx);
	pi ans;
	centry(vertx, g, ans, count);
	return { ans.second, ans.first };
}

vi parent;
vi rang;

void make_set(int v) {
	parent[v] = v;
	rang[v] = 0;
}

int find_set(int v) {
	if (v == parent[v])
		return v;
	return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
	a = find_set(a);
	b = find_set(b);
	if (a != b) {
		parent[b] = a;
	}
}

map<pi, ll> path;
vi a;
ll getPath(ll v, ll u) {
	if (path.find({ u,v }) == path.end()) {
		return a[v] + a[u];
	}
	return min(a[v] + a[u], path[{u, v}]);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	freopen("output.txt", "r", stdin);
	ll n, m;
	cin >> n >> m;
	a = vi(n);
	ll core = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] < a[core]) {
			core = i;
		}
	}
	vvi matr(n, vi());
	for (int i = 0; i < m; i++) {
		ll x, y, c;
		cin >> x >> y >> c;
		x--; y--;
		if ((path.find({ x,y }) == path.end() && c<a[x]+a[y]) || (path.find({ x,y }) != path.end() && path[{x, y}] > c)){
			matr[x].push_back(y);
			matr[y].push_back(x);
			path[{y, x}] = c;
			path[{x, y}] = c;
		}
	}
	parent = vi(n);
	rang = vi(n);
	for (int i = 0; i < n; i++) {
		make_set(i);
	}
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		if (i == core) {
			continue;
		}
		if (i != find_set(i)) {
			continue;
		}
		ll path2 = getPath(core, i);
		pi minC = {core,path2};
		for (ll v : matr[i]) {
			if (v == core) {
				continue;
			}
			ll c = getPath(i, v);
			if (c < minC.second) {
				minC.second = c;
				minC.first = v;
			}
		}

		if (minC.first!=core) {
			ll v = find_set(minC.first);
			if (v == i) {
				continue;
			}
			ll p1 = getPath(core, v);
			ll p2 = getPath(core, i);
			if (p1 < p2 ){
				union_sets(v, i);
			}
			else {
				union_sets(i, v);
			}
			sum += minC.second;
		}
	}

	for (int i = 0; i < n; i++) {
		if (i == core) {
			continue;
		}
		if (parent[i] == i) {
			sum += getPath(core, i);
		}
	}
	cout << sum;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#define endl '\n'

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pi;
typedef pair<pi, ll> ppi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<vpi> vvpi;
typedef vector<ppi> vppi;
typedef vector<bool> vb;
typedef map<ll, ll> mii;
typedef set<pi> spi;
typedef set<ll> si;
typedef vector<si> vsi;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using Mi = map<ll, T>;
template <typename T> using MMi = map<ll, Mi<T>>;

/*
int main() {
	printTest();
	return 0;
}
*/
//ios::sync_with_stdio(false);
//cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
vi tree;

void build(vi &arr, ll ind, ll l, ll r) {
	if (l == r) {
		tree[ind] = arr[l];
		return;
	}
	ll mid = (l + r) / 2;
	build(arr, ind * 2, l, mid);
	build(arr, ind * 2 + 1, mid + 1, r);
	tree[ind] = max(tree[ind * 2], tree[ind * 2 + 1]);
}
ll getMax(ll ind, ll tl, ll tr, ll l, ll r) {
	if (l > r)
		return 0;
	if (l == tl && r == tr)
		return tree[ind];
	ll tm = (tl + tr) / 2;
	ll a = getMax(ind * 2, tl, tm, l, min(r, tm));
	ll b = getMax(ind * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
	return max(a, b);
}

vb prim;
void er() {
	ll n = 1e6;
	prim = vb(n + 1, true);
	prim[0] = prim[1] = false;
	for (ll i = 2; i <= n; i++) {
		if (prim[i]) {
			for (ll j = i * i; j <= n; j += i) {
				prim[j] = false;
			}
		}
	}
}
vi topSort(ll v, V<si> &g) {
	vi ans;
	vb viz(g.size(),false);
	//dfs(v, g, viz, ans);
	return ans;
}
ll rast(pi &a, pi &b) {
	return abs(a.first - b.first) + abs(a.second - b.second);
}
vi z_function(string &s) {
	ll n = s.length();
	vi z(n,0);
	ll l = 0, r = 0;
	for (ll i = 1; i < n; i++) {
		if (i <= r) {
			z[i] = min(r - i + 1, z[i - l]);
		}
		while (i+z[i]<n && s[z[i]] == s[z[i]+i]) {
			z[i]++;
		}
		if (i + z[i] - 1 > r) {
			l = i;
			r = i + z[i] - 1;
		}
	}
	return z;
}
bool comp(const string &a, const string &b) {
	return a.size() < b.size();
}

void printTest() {
	freopen("output.txt", "w", stdout);
	cout << "1000 500 1000" << endl;
	for (int i = 0; i < 500; i++) {
		cout << i*2 << " " << i*2 + 1 << endl;
	}
	for (int i = 0; i < 1000; i++) {
		cout << i << " " << 1000 - i << endl;
	}
}

ll getDiam(ll v, vvi &g, vb &viz, vi &ans) {
	viz[v] = true;
	multiset<pi> m;
	ll ret = 0;
	for (ll u : g[v]) {
		if (!viz[u]) {
			ll glub = getDiam(u, g, viz, ans)+1;
			ret = max(ret, glub);
			m.insert({ glub,u });
			if (m.size() > 2) {
				m.erase(m.begin());
			}

		}
	}
	ll diam = 0;
	for (pi a : m) {
		diam += a.first;
	}
	ans[v] = diam;
	return ret;
}
void createVertx(ll v, vsi &g, vb &viz, vi &vertx) {
	vertx.push_back(v);
	viz[v] = true;
	for (ll u : g[v]) {
		if (!viz[u]) {
			createVertx(u, g, viz, vertx);
		}
	}
}
void centry(vi &vertx, vsi g, pi &ans, vi &count) {

	spi lists;
	for (ll v : vertx) {
		lists.insert({ count[v],v });
	}

	ll rad = 0;
	while (lists.size() > 2) {
		rad++;
		si del;
		while (lists.begin()->first==1) {
			del.insert(lists.begin()->second);
			lists.erase(lists.begin());
		}
		for (ll v : del) {
			ll u = *g[v].begin();
			pi p;
			p.first = count[u];
			p.second = u;
			lists.erase(p);
			count[u]--;
			g[u].erase(v);
			lists.insert({ count[u],u });
		}
	}
	ans.first = lists.begin()->second;
	if (lists.size() == 2) {
		rad++;
	}
	ans.second = rad;
}

pi getCentry(ll v, vsi &g, vb &viz, vi &count) {
	vi vertx;
	createVertx(v, g, viz, vertx);
	pi ans;
	centry(vertx, g, ans, count);
	return { ans.second, ans.first };
}

vi parent;
vi rang;

void make_set(int v) {
	parent[v] = v;
	rang[v] = 0;
}

int find_set(int v) {
	if (v == parent[v])
		return v;
	return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
	a = find_set(a);
	b = find_set(b);
	if (a != b) {
		parent[b] = a;
	}
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n, m;
	cin >> n >> m;
	vi a(n);
	ll core = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] < a[core]) {
			core = i;
		}
	}
	vvpi matr(n, vpi());
	for (int i = 0; i < m; i++) {
		ll x, y, c;
		cin >> x >> y >> c;
		x--; y--;
		matr[x].push_back({ y,c });
		matr[y].push_back({ x,c });
	}
	parent = vi(n);
	rang = vi(n);
	for (int i = 0; i < n; i++) {
		make_set(i);
	}
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		if (i == core) {
			continue;
		}
		ll soed = (a[i] + a[core]);
		pi minC = {core,soed};
		for (pi p : matr[i]) {
			ll v = p.first;
			ll c = p.second;
			if (c < minC.second) {
				minC.second = c;
				minC.first = v;
			}
		}
		if (minC.second!=soed) {
			if (minC.first == core) {
				sum += minC.second;
				continue;
			}
			ll v = find_set(minC.first);
			if (a[v] < a[i] || (a[v]==a[i]&&i<v)) {
				union_sets(v, i);
				sum += minC.second;
				continue;
			}
		}
		sum += soed;
	}
	cout << sum;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#define endl '\n'

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pi;
typedef pair<pi, ll> ppi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<vpi> vvpi;
typedef vector<ppi> vppi;
typedef vector<bool> vb;
typedef map<ll, ll> mii;
typedef set<pi> spi;
typedef set<ll> si;
typedef vector<si> vsi;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using Mi = map<ll, T>;
template <typename T> using MMi = map<ll, Mi<T>>;

/*
int main() {
	printTest();
	return 0;
}
*/
//ios::sync_with_stdio(false);
//cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
vi tree;

void build(vi &arr, ll ind, ll l, ll r) {
	if (l == r) {
		tree[ind] = arr[l];
		return;
	}
	ll mid = (l + r) / 2;
	build(arr, ind * 2, l, mid);
	build(arr, ind * 2 + 1, mid + 1, r);
	tree[ind] = max(tree[ind * 2], tree[ind * 2 + 1]);
}
ll getMax(ll ind, ll tl, ll tr, ll l, ll r) {
	if (l > r)
		return 0;
	if (l == tl && r == tr)
		return tree[ind];
	ll tm = (tl + tr) / 2;
	ll a = getMax(ind * 2, tl, tm, l, min(r, tm));
	ll b = getMax(ind * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
	return max(a, b);
}

vb prim;
void er() {
	ll n = 1e6;
	prim = vb(n + 1, true);
	prim[0] = prim[1] = false;
	for (ll i = 2; i <= n; i++) {
		if (prim[i]) {
			for (ll j = i * i; j <= n; j += i) {
				prim[j] = false;
			}
		}
	}
}
vi topSort(ll v, V<si> &g) {
	vi ans;
	vb viz(g.size(),false);
	//dfs(v, g, viz, ans);
	return ans;
}
ll rast(pi &a, pi &b) {
	return abs(a.first - b.first) + abs(a.second - b.second);
}
vi z_function(string &s) {
	ll n = s.length();
	vi z(n,0);
	ll l = 0, r = 0;
	for (ll i = 1; i < n; i++) {
		if (i <= r) {
			z[i] = min(r - i + 1, z[i - l]);
		}
		while (i+z[i]<n && s[z[i]] == s[z[i]+i]) {
			z[i]++;
		}
		if (i + z[i] - 1 > r) {
			l = i;
			r = i + z[i] - 1;
		}
	}
	return z;
}
bool comp(const string &a, const string &b) {
	return a.size() < b.size();
}

void printTest() {
	freopen("output.txt", "w", stdout);
	cout << "1000 500 1000" << endl;
	for (int i = 0; i < 500; i++) {
		cout << i*2 << " " << i*2 + 1 << endl;
	}
	for (int i = 0; i < 1000; i++) {
		cout << i << " " << 1000 - i << endl;
	}
}

ll getDiam(ll v, vvi &g, vb &viz, vi &ans) {
	viz[v] = true;
	multiset<pi> m;
	ll ret = 0;
	for (ll u : g[v]) {
		if (!viz[u]) {
			ll glub = getDiam(u, g, viz, ans)+1;
			ret = max(ret, glub);
			m.insert({ glub,u });
			if (m.size() > 2) {
				m.erase(m.begin());
			}

		}
	}
	ll diam = 0;
	for (pi a : m) {
		diam += a.first;
	}
	ans[v] = diam;
	return ret;
}
void createVertx(ll v, vsi &g, vb &viz, vi &vertx) {
	vertx.push_back(v);
viz[v] = true;
for (ll u : g[v]) {
	if (!viz[u]) {
		createVertx(u, g, viz, vertx);
	}
}
}
void centry(vi &vertx, vsi g, pi &ans, vi &count) {

	spi lists;
	for (ll v : vertx) {
		lists.insert({ count[v],v });
	}

	ll rad = 0;
	while (lists.size() > 2) {
		rad++;
		si del;
		while (lists.begin()->first == 1) {
			del.insert(lists.begin()->second);
			lists.erase(lists.begin());
		}
		for (ll v : del) {
			ll u = *g[v].begin();
			pi p;
			p.first = count[u];
			p.second = u;
			lists.erase(p);
			count[u]--;
			g[u].erase(v);
			lists.insert({ count[u],u });
		}
	}
	ans.first = lists.begin()->second;
	if (lists.size() == 2) {
		rad++;
	}
	ans.second = rad;
}

pi getCentry(ll v, vsi &g, vb &viz, vi &count) {
	vi vertx;
	createVertx(v, g, viz, vertx);
	pi ans;
	centry(vertx, g, ans, count);
	return { ans.second, ans.first };
}

vi parent;
vi rang;

void make_set(int v) {
	parent[v] = v;
	rang[v] = 0;
}

int find_set(int v) {
	if (v == parent[v])
		return v;
	return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
	a = find_set(a);
	b = find_set(b);
	if (a != b) {
		parent[b] = a;
	}
}

map<pi, ll> path;
vi a;
ll getPath(ll v, ll u) {
	if (path.find({ u,v }) == path.end()) {
		return a[v] + a[u];
	}
	return min(a[v] + a[u], path[{u, v}]);
}

void obed() {

}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//freopen("output.txt", "r", stdin);
	ll n, m;
	cin >> n >> m;
	a = vi(n);
	ll core = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] < a[core]) {
			core = i;
		}
	}
	vvi matr(n, vi());
	for (int i = 0; i < m; i++) {
		ll x, y, c;
		cin >> x >> y >> c;
		x--; y--;
		if ((path.find({ x,y }) == path.end() && c<a[x]+a[y]) || (path.find({ x,y }) != path.end() && path[{x, y}] > c)){
			matr[x].push_back(y);
			matr[y].push_back(x);
			path[{y, x}] = c;
			path[{x, y}] = c;
		}
	}
	parent = vi(n);
	rang = vi(n);
	for (int i = 0; i < n; i++) {
		make_set(i);
	}
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		if (i == core) {
			continue;
		}
		ll path2 = getPath(core, find_set(i));
		pi minC = {core,path2};
		for (ll v : matr[i]) {
			if (v == core) {
				continue;
			}
			ll c = getPath(i, v);
			if (c < minC.second) {
				minC.second = c;
				minC.first = v;
				ll vv = find_set(minC.first);
				if (vv == i) {
					continue;
				}
				ll p1 = getPath(core, v);
				ll p2 = getPath(core, i);
				if (p1 < p2) {
					union_sets(v, i);
					sum += minC.second;
				}
			}
		}
	}

	for (int i = 0; i < n; i++) {
		if (i == core) {
			continue;
		}
		if (parent[i] == i) {
			sum += getPath(core, i);
		}
	}
	cout << sum;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#define endl '\n'

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pi;
typedef pair<pi, ll> ppi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<vpi> vvpi;
typedef vector<ppi> vppi;
typedef vector<bool> vb;
typedef map<ll, ll> mii;
typedef set<pi> spi;
typedef set<ll> si;
typedef vector<si> vsi;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using Mi = map<ll, T>;
template <typename T> using MMi = map<ll, Mi<T>>;

/*
int main() {
	printTest();
	return 0;
}
*/
//ios::sync_with_stdio(false);
//cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
vi tree;

void build(vi &arr, ll ind, ll l, ll r) {
	if (l == r) {
		tree[ind] = arr[l];
		return;
	}
	ll mid = (l + r) / 2;
	build(arr, ind * 2, l, mid);
	build(arr, ind * 2 + 1, mid + 1, r);
	tree[ind] = max(tree[ind * 2], tree[ind * 2 + 1]);
}
ll getMax(ll ind, ll tl, ll tr, ll l, ll r) {
	if (l > r)
		return 0;
	if (l == tl && r == tr)
		return tree[ind];
	ll tm = (tl + tr) / 2;
	ll a = getMax(ind * 2, tl, tm, l, min(r, tm));
	ll b = getMax(ind * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
	return max(a, b);
}

vb prim;
void er() {
	ll n = 1e6;
	prim = vb(n + 1, true);
	prim[0] = prim[1] = false;
	for (ll i = 2; i <= n; i++) {
		if (prim[i]) {
			for (ll j = i * i; j <= n; j += i) {
				prim[j] = false;
			}
		}
	}
}
vi topSort(ll v, V<si> &g) {
	vi ans;
	vb viz(g.size(),false);
	//dfs(v, g, viz, ans);
	return ans;
}
ll rast(pi &a, pi &b) {
	return abs(a.first - b.first) + abs(a.second - b.second);
}
vi z_function(string &s) {
	ll n = s.length();
	vi z(n,0);
	ll l = 0, r = 0;
	for (ll i = 1; i < n; i++) {
		if (i <= r) {
			z[i] = min(r - i + 1, z[i - l]);
		}
		while (i+z[i]<n && s[z[i]] == s[z[i]+i]) {
			z[i]++;
		}
		if (i + z[i] - 1 > r) {
			l = i;
			r = i + z[i] - 1;
		}
	}
	return z;
}
bool comp(const string &a, const string &b) {
	return a.size() < b.size();
}

void printTest() {
	freopen("output.txt", "w", stdout);
	cout << "1000 500 1000" << endl;
	for (int i = 0; i < 500; i++) {
		cout << i*2 << " " << i*2 + 1 << endl;
	}
	for (int i = 0; i < 1000; i++) {
		cout << i << " " << 1000 - i << endl;
	}
}

ll getDiam(ll v, vvi &g, vb &viz, vi &ans) {
	viz[v] = true;
	multiset<pi> m;
	ll ret = 0;
	for (ll u : g[v]) {
		if (!viz[u]) {
			ll glub = getDiam(u, g, viz, ans)+1;
			ret = max(ret, glub);
			m.insert({ glub,u });
			if (m.size() > 2) {
				m.erase(m.begin());
			}

		}
	}
	ll diam = 0;
	for (pi a : m) {
		diam += a.first;
	}
	ans[v] = diam;
	return ret;
}
void createVertx(ll v, vsi &g, vb &viz, vi &vertx) {
	vertx.push_back(v);
viz[v] = true;
for (ll u : g[v]) {
	if (!viz[u]) {
		createVertx(u, g, viz, vertx);
	}
}
}
void centry(vi &vertx, vsi g, pi &ans, vi &count) {

	spi lists;
	for (ll v : vertx) {
		lists.insert({ count[v],v });
	}

	ll rad = 0;
	while (lists.size() > 2) {
		rad++;
		si del;
		while (lists.begin()->first == 1) {
			del.insert(lists.begin()->second);
			lists.erase(lists.begin());
		}
		for (ll v : del) {
			ll u = *g[v].begin();
			pi p;
			p.first = count[u];
			p.second = u;
			lists.erase(p);
			count[u]--;
			g[u].erase(v);
			lists.insert({ count[u],u });
		}
	}
	ans.first = lists.begin()->second;
	if (lists.size() == 2) {
		rad++;
	}
	ans.second = rad;
}

pi getCentry(ll v, vsi &g, vb &viz, vi &count) {
	vi vertx;
	createVertx(v, g, viz, vertx);
	pi ans;
	centry(vertx, g, ans, count);
	return { ans.second, ans.first };
}

vi parent;
vi rang;

void make_set(int v) {
	parent[v] = v;
	rang[v] = 0;
}

int find_set(int v) {
	if (v == parent[v])
		return v;
	return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
	a = find_set(a);
	b = find_set(b);
	if (a != b) {
		parent[b] = a;
	}
}

map<pi, ll> path;
vi a;
ll getPath(ll v, ll u) {
	if (path.find({ u,v }) == path.end()) {
		return a[v] + a[u];
	}
	return min(a[v] + a[u], path[{u, v}]);
}

void obed() {

}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//freopen("output.txt", "r", stdin);
	ll n, m;
	cin >> n >> m;
	a = vi(n);
	ll core = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] < a[core]) {
			core = i;
		}
	}
	vvi matr(n, vi());
	for (int i = 0; i < m; i++) {
		ll x, y, c;
		cin >> x >> y >> c;
		x--; y--;
		if ((path.find({ x,y }) == path.end() && c<a[x]+a[y]) || (path.find({ x,y }) != path.end() && path[{x, y}] > c)){
			matr[x].push_back(y);
			matr[y].push_back(x);
			path[{y, x}] = c;
			path[{x, y}] = c;
		}
	}
	parent = vi(n);
	rang = vi(n);
	for (int i = 0; i < n; i++) {
		make_set(i);
	}
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		if (i == core) {
			continue;
		}
		for (ll v : matr[i]) {
			if (v == core) {
				continue;
			}
			ll path2 = getPath(core, find_set(i));
			ll c = getPath(i, v);
			if (c < path2) {
				ll vv = find_set(v);
				if (vv == i) {
					continue;
				}
				ll p1 = getPath(core, vv);
				if (p1 < path2) {
					union_sets(v, i);
					sum += c;
				}
			}
		}
	}

	for (int i = 0; i < n; i++) {
		if (i == core) {
			continue;
		}
		if (parent[i] == i) {
			sum += getPath(core, i);
		}
	}
	cout << sum;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#define endl '\n'

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pi;
typedef pair<pi, ll> ppi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<vpi> vvpi;
typedef vector<ppi> vppi;
typedef vector<bool> vb;
typedef map<ll, ll> mii;
typedef set<pi> spi;
typedef set<ll> si;
typedef vector<si> vsi;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using Mi = map<ll, T>;
template <typename T> using MMi = map<ll, Mi<T>>;

/*
int main() {
	printTest();
	return 0;
}
*/
//ios::sync_with_stdio(false);
//cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
vi tree;

void build(vi &arr, ll ind, ll l, ll r) {
	if (l == r) {
		tree[ind] = arr[l];
		return;
	}
	ll mid = (l + r) / 2;
	build(arr, ind * 2, l, mid);
	build(arr, ind * 2 + 1, mid + 1, r);
	tree[ind] = max(tree[ind * 2], tree[ind * 2 + 1]);
}
ll getMax(ll ind, ll tl, ll tr, ll l, ll r) {
	if (l > r)
		return 0;
	if (l == tl && r == tr)
		return tree[ind];
	ll tm = (tl + tr) / 2;
	ll a = getMax(ind * 2, tl, tm, l, min(r, tm));
	ll b = getMax(ind * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
	return max(a, b);
}

vb prim;
void er() {
	ll n = 1e6;
	prim = vb(n + 1, true);
	prim[0] = prim[1] = false;
	for (ll i = 2; i <= n; i++) {
		if (prim[i]) {
			for (ll j = i * i; j <= n; j += i) {
				prim[j] = false;
			}
		}
	}
}
vi topSort(ll v, V<si> &g) {
	vi ans;
	vb viz(g.size(),false);
	//dfs(v, g, viz, ans);
	return ans;
}
ll rast(pi &a, pi &b) {
	return abs(a.first - b.first) + abs(a.second - b.second);
}
vi z_function(string &s) {
	ll n = s.length();
	vi z(n,0);
	ll l = 0, r = 0;
	for (ll i = 1; i < n; i++) {
		if (i <= r) {
			z[i] = min(r - i + 1, z[i - l]);
		}
		while (i+z[i]<n && s[z[i]] == s[z[i]+i]) {
			z[i]++;
		}
		if (i + z[i] - 1 > r) {
			l = i;
			r = i + z[i] - 1;
		}
	}
	return z;
}
bool comp(const string &a, const string &b) {
	return a.size() < b.size();
}

void printTest() {
	freopen("output.txt", "w", stdout);
	cout << "1000 500 1000" << endl;
	for (int i = 0; i < 500; i++) {
		cout << i*2 << " " << i*2 + 1 << endl;
	}
	for (int i = 0; i < 1000; i++) {
		cout << i << " " << 1000 - i << endl;
	}
}

ll getDiam(ll v, vvi &g, vb &viz, vi &ans) {
	viz[v] = true;
	multiset<pi> m;
	ll ret = 0;
	for (ll u : g[v]) {
		if (!viz[u]) {
			ll glub = getDiam(u, g, viz, ans)+1;
			ret = max(ret, glub);
			m.insert({ glub,u });
			if (m.size() > 2) {
				m.erase(m.begin());
			}

		}
	}
	ll diam = 0;
	for (pi a : m) {
		diam += a.first;
	}
	ans[v] = diam;
	return ret;
}
void createVertx(ll v, vsi &g, vb &viz, vi &vertx) {
	vertx.push_back(v);
viz[v] = true;
for (ll u : g[v]) {
	if (!viz[u]) {
		createVertx(u, g, viz, vertx);
	}
}
}
void centry(vi &vertx, vsi g, pi &ans, vi &count) {

	spi lists;
	for (ll v : vertx) {
		lists.insert({ count[v],v });
	}

	ll rad = 0;
	while (lists.size() > 2) {
		rad++;
		si del;
		while (lists.begin()->first == 1) {
			del.insert(lists.begin()->second);
			lists.erase(lists.begin());
		}
		for (ll v : del) {
			ll u = *g[v].begin();
			pi p;
			p.first = count[u];
			p.second = u;
			lists.erase(p);
			count[u]--;
			g[u].erase(v);
			lists.insert({ count[u],u });
		}
	}
	ans.first = lists.begin()->second;
	if (lists.size() == 2) {
		rad++;
	}
	ans.second = rad;
}

pi getCentry(ll v, vsi &g, vb &viz, vi &count) {
	vi vertx;
	createVertx(v, g, viz, vertx);
	pi ans;
	centry(vertx, g, ans, count);
	return { ans.second, ans.first };
}

vi parent;
vi rang;

void make_set(int v) {
	parent[v] = v;
	rang[v] = 0;
}

int find_set(int v) {
	if (v == parent[v])
		return v;
	return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
	a = find_set(a);
	b = find_set(b);
	if (a != b) {
		parent[b] = a;
	}
}

map<pi, ll> path;
vi a;
ll getPath(ll v, ll u) {
	if (path.find({ u,v }) == path.end()) {
		return a[v] + a[u];
	}
	return min(a[v] + a[u], path[{u, v}]);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//freopen("output.txt", "r", stdin);
	ll n, m;
	cin >> n >> m;
	a = vi(n);
	ll core = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] < a[core]) {
			core = i;
		}
	}
	vvi matr(n, vi());
	for (int i = 0; i < m; i++) {
		ll x, y, c;
		cin >> x >> y >> c;
		x--; y--;
		if ((path.find({ x,y }) == path.end() && c<a[x]+a[y]) || (path.find({ x,y }) != path.end() && path[{x, y}] > c)){
			matr[x].push_back(y);
			matr[y].push_back(x);
			path[{y, x}] = c;
			path[{x, y}] = c;
		}
	}
	parent = vi(n);
	rang = vi(n);
	for (int i = 0; i < n; i++) {
		make_set(i);
	}
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		if (i == core) {
			continue;
		}
		ll path2 = getPath(core, i);
		pi minC = {core,path2};
		for (ll v : matr[i]) {
			if (v == core) {
				continue;
			}
			ll c = getPath(i, v);
			if (c < minC.second) {
				minC.second = c;
				minC.first = v;
			}
		}

		if (minC.first!=core) {
			ll v = find_set(minC.first);
			if (v == i) {
				continue;
			}
			ll p1 = getPath(core, v);
			ll p2 = getPath(core, i);
			if (p1 < p2 ){
				union_sets(v, i);
			}
			else {
				union_sets(i, v);
			}
			sum += minC.second;
		}
	}
	for (int i = 0; i < n; i++) {
		if (i == core) {
			continue;
		}
		if (parent[i] == i) {
			sum += getPath(core, i);
		}
	}
	cout << sum;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#define endl '\n'

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pi;
typedef pair<pi, ll> ppi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<vpi> vvpi;
typedef vector<ppi> vppi;
typedef vector<bool> vb;
typedef map<ll, ll> mii;
typedef set<pi> spi;
typedef set<ll> si;
typedef vector<si> vsi;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using Mi = map<ll, T>;
template <typename T> using MMi = map<ll, Mi<T>>;

/*
int main() {
	printTest();
	return 0;
}
*/
//ios::sync_with_stdio(false);
//cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
vi tree;

void build(vi &arr, ll ind, ll l, ll r) {
	if (l == r) {
		tree[ind] = arr[l];
		return;
	}
	ll mid = (l + r) / 2;
	build(arr, ind * 2, l, mid);
	build(arr, ind * 2 + 1, mid + 1, r);
	tree[ind] = max(tree[ind * 2], tree[ind * 2 + 1]);
}
ll getMax(ll ind, ll tl, ll tr, ll l, ll r) {
	if (l > r)
		return 0;
	if (l == tl && r == tr)
		return tree[ind];
	ll tm = (tl + tr) / 2;
	ll a = getMax(ind * 2, tl, tm, l, min(r, tm));
	ll b = getMax(ind * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
	return max(a, b);
}

vb prim;
void er() {
	ll n = 1e6;
	prim = vb(n + 1, true);
	prim[0] = prim[1] = false;
	for (ll i = 2; i <= n; i++) {
		if (prim[i]) {
			for (ll j = i * i; j <= n; j += i) {
				prim[j] = false;
			}
		}
	}
}
vi topSort(ll v, V<si> &g) {
	vi ans;
	vb viz(g.size(),false);
	//dfs(v, g, viz, ans);
	return ans;
}
ll rast(pi &a, pi &b) {
	return abs(a.first - b.first) + abs(a.second - b.second);
}
vi z_function(string &s) {
	ll n = s.length();
	vi z(n,0);
	ll l = 0, r = 0;
	for (ll i = 1; i < n; i++) {
		if (i <= r) {
			z[i] = min(r - i + 1, z[i - l]);
		}
		while (i+z[i]<n && s[z[i]] == s[z[i]+i]) {
			z[i]++;
		}
		if (i + z[i] - 1 > r) {
			l = i;
			r = i + z[i] - 1;
		}
	}
	return z;
}
bool comp(const string &a, const string &b) {
	return a.size() < b.size();
}

void printTest() {
	freopen("output.txt", "w", stdout);
	cout << "1000 500 1000" << endl;
	for (int i = 0; i < 500; i++) {
		cout << i*2 << " " << i*2 + 1 << endl;
	}
	for (int i = 0; i < 1000; i++) {
		cout << i << " " << 1000 - i << endl;
	}
}

ll getDiam(ll v, vvi &g, vb &viz, vi &ans) {
	viz[v] = true;
	multiset<pi> m;
	ll ret = 0;
	for (ll u : g[v]) {
		if (!viz[u]) {
			ll glub = getDiam(u, g, viz, ans)+1;
			ret = max(ret, glub);
			m.insert({ glub,u });
			if (m.size() > 2) {
				m.erase(m.begin());
			}

		}
	}
	ll diam = 0;
	for (pi a : m) {
		diam += a.first;
	}
	ans[v] = diam;
	return ret;
}
void createVertx(ll v, vsi &g, vb &viz, vi &vertx) {
	vertx.push_back(v);
	viz[v] = true;
	for (ll u : g[v]) {
		if (!viz[u]) {
			createVertx(u, g, viz, vertx);
		}
	}
}
void centry(vi &vertx, vsi g, pi &ans, vi &count) {

	spi lists;
	for (ll v : vertx) {
		lists.insert({ count[v],v });
	}

	ll rad = 0;
	while (lists.size() > 2) {
		rad++;
		si del;
		while (lists.begin()->first==1) {
			del.insert(lists.begin()->second);
			lists.erase(lists.begin());
		}
		for (ll v : del) {
			ll u = *g[v].begin();
			pi p;
			p.first = count[u];
			p.second = u;
			lists.erase(p);
			count[u]--;
			g[u].erase(v);
			lists.insert({ count[u],u });
		}
	}
	ans.first = lists.begin()->second;
	if (lists.size() == 2) {
		rad++;
	}
	ans.second = rad;
}

pi getCentry(ll v, vsi &g, vb &viz, vi &count) {
	vi vertx;
	createVertx(v, g, viz, vertx);
	pi ans;
	centry(vertx, g, ans, count);
	return { ans.second, ans.first };
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n, m;
	cin >> n >> m;
	vi a(n);
	ll core = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] < a[core]) {
			core = i;
		}
	}
	vvpi matr(n, vpi());
	for (int i = 0; i < m; i++) {
		ll x, y, c;
		cin >> x >> y >> c;
		x--; y--;
		matr[x].push_back({ y,c });
		matr[y].push_back({ x,c });
	}
	vi parent(n);
	for (int i = 0; i < n; i++) {
		parent[i] = i;
	}
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		if (i == core) {
			continue;
		}
		ll soed = (a[i] + a[core]);
		pi minC = {core,soed};
		for (pi p : matr[i]) {
			ll v = p.first;
			ll c = p.second;
			if (c < minC.second) {
				minC.second = c;
				minC.first = v;
			}
		}
		if (minC.second!=soed) {
			if (minC.first == core) {
				sum += minC.second;
				continue;
			}
			ll v = parent[minC.first];
			if (a[v] < a[i] || (a[v]==a[i]&&i<v)) {
				ll b = 0;
				if (i == v) {
					ll c = 5 / b;
				}
				parent[i] = v;
				sum += minC.second;
				continue;
			}
		}
		sum += soed;
	}
	cout << sum;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#define endl '\n'

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pi;
typedef pair<pi, ll> ppi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<vpi> vvpi;
typedef vector<ppi> vppi;
typedef vector<bool> vb;
typedef map<ll, ll> mii;
typedef set<pi> spi;
typedef set<ll> si;
typedef vector<si> vsi;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using Mi = map<ll, T>;
template <typename T> using MMi = map<ll, Mi<T>>;

/*
int main() {
	printTest();
	return 0;
}
*/
//ios::sync_with_stdio(false);
//cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
vi tree;

void build(vi &arr, ll ind, ll l, ll r) {
	if (l == r) {
		tree[ind] = arr[l];
		return;
	}
	ll mid = (l + r) / 2;
	build(arr, ind * 2, l, mid);
	build(arr, ind * 2 + 1, mid + 1, r);
	tree[ind] = max(tree[ind * 2], tree[ind * 2 + 1]);
}
ll getMax(ll ind, ll tl, ll tr, ll l, ll r) {
	if (l > r)
		return 0;
	if (l == tl && r == tr)
		return tree[ind];
	ll tm = (tl + tr) / 2;
	ll a = getMax(ind * 2, tl, tm, l, min(r, tm));
	ll b = getMax(ind * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
	return max(a, b);
}

vb prim;
void er() {
	ll n = 1e6;
	prim = vb(n + 1, true);
	prim[0] = prim[1] = false;
	for (ll i = 2; i <= n; i++) {
		if (prim[i]) {
			for (ll j = i * i; j <= n; j += i) {
				prim[j] = false;
			}
		}
	}
}
vi topSort(ll v, V<si> &g) {
	vi ans;
	vb viz(g.size(),false);
	//dfs(v, g, viz, ans);
	return ans;
}
ll rast(pi &a, pi &b) {
	return abs(a.first - b.first) + abs(a.second - b.second);
}
vi z_function(string &s) {
	ll n = s.length();
	vi z(n,0);
	ll l = 0, r = 0;
	for (ll i = 1; i < n; i++) {
		if (i <= r) {
			z[i] = min(r - i + 1, z[i - l]);
		}
		while (i+z[i]<n && s[z[i]] == s[z[i]+i]) {
			z[i]++;
		}
		if (i + z[i] - 1 > r) {
			l = i;
			r = i + z[i] - 1;
		}
	}
	return z;
}
bool comp(const string &a, const string &b) {
	return a.size() < b.size();
}

void printTest() {
	freopen("output.txt", "w", stdout);
	cout << "1000 500 1000" << endl;
	for (int i = 0; i < 500; i++) {
		cout << i*2 << " " << i*2 + 1 << endl;
	}
	for (int i = 0; i < 1000; i++) {
		cout << i << " " << 1000 - i << endl;
	}
}

ll getDiam(ll v, vvi &g, vb &viz, vi &ans) {
	viz[v] = true;
	multiset<pi> m;
	ll ret = 0;
	for (ll u : g[v]) {
		if (!viz[u]) {
			ll glub = getDiam(u, g, viz, ans)+1;
			ret = max(ret, glub);
			m.insert({ glub,u });
			if (m.size() > 2) {
				m.erase(m.begin());
			}

		}
	}
	ll diam = 0;
	for (pi a : m) {
		diam += a.first;
	}
	ans[v] = diam;
	return ret;
}
void createVertx(ll v, vsi &g, vb &viz, vi &vertx) {
	vertx.push_back(v);
viz[v] = true;
for (ll u : g[v]) {
	if (!viz[u]) {
		createVertx(u, g, viz, vertx);
	}
}
}
void centry(vi &vertx, vsi g, pi &ans, vi &count) {

	spi lists;
	for (ll v : vertx) {
		lists.insert({ count[v],v });
	}

	ll rad = 0;
	while (lists.size() > 2) {
		rad++;
		si del;
		while (lists.begin()->first == 1) {
			del.insert(lists.begin()->second);
			lists.erase(lists.begin());
		}
		for (ll v : del) {
			ll u = *g[v].begin();
			pi p;
			p.first = count[u];
			p.second = u;
			lists.erase(p);
			count[u]--;
			g[u].erase(v);
			lists.insert({ count[u],u });
		}
	}
	ans.first = lists.begin()->second;
	if (lists.size() == 2) {
		rad++;
	}
	ans.second = rad;
}

pi getCentry(ll v, vsi &g, vb &viz, vi &count) {
	vi vertx;
	createVertx(v, g, viz, vertx);
	pi ans;
	centry(vertx, g, ans, count);
	return { ans.second, ans.first };
}

vi parent;
vi rang;

void make_set(int v) {
	parent[v] = v;
	rang[v] = 0;
}

int find_set(int v) {
	if (v == parent[v])
		return v;
	return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
	a = find_set(a);
	b = find_set(b);
	if (a != b) {
		parent[b] = a;
	}
}

map<pi, ll> path;
vi a;
ll getPath(ll v, ll u) {
	if (path.find({ u,v }) == path.end()) {
		return a[v] + a[u];
	}
	return min(a[v] + a[u], path[{u, v}]);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//freopen("output.txt", "r", stdin);
	ll n, m;
	cin >> n >> m;
	a = vi(n);
	ll core = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] < a[core]) {
			core = i;
		}
	}
	vvi matr(n, vi());
	for (int i = 0; i < m; i++) {
		ll x, y, c;
		cin >> x >> y >> c;
		x--; y--;
		if ((path.find({ x,y }) == path.end() && c<a[x]+a[y]) || (path.find({ x,y }) != path.end() && path[{x, y}] > c)){
			matr[x].push_back(y);
			matr[y].push_back(x);
			path[{y, x}] = c;
			path[{x, y}] = c;
		}
	}
	parent = vi(n);
	rang = vi(n);
	for (int i = 0; i < n; i++) {
		make_set(i);
	}
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		if (i == core) {
			continue;
		}
		ll path2 = getPath(core, i);
		pi minC = {core,path2};
		for (ll v : matr[i]) {
			if (v == core) {
				continue;
			}
			ll c = getPath(i, v);
			if (c < minC.second) {
				minC.second = c;
				minC.first = v;
			}
		}

		if (minC.first!=core) {
			ll v = find_set(minC.first);
			if (v == i) {
				continue;
			}
			ll p1 = getPath(core, v);
			ll p2 = getPath(core, i);
			if (p1 < p2 ){
				union_sets(v, i);
			}
			else {
				union_sets(i, v);
			}
			sum += minC.second;
			path[{i, minC.first}] = 1e18;
			path[{minC.first, i}] = 1e18;
		}
	}

	for (int i = 0; i < n; i++) {
		if (i == core) {
			continue;
		}
		if (parent[i] == i) {
			sum += getPath(core, i);
		}
	}
	cout << sum;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#define endl '\n'

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pi;
typedef pair<pi, ll> ppi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<vpi> vvpi;
typedef vector<ppi> vppi;
typedef vector<bool> vb;
typedef map<ll, ll> mii;
typedef set<pi> spi;
typedef set<ll> si;
typedef vector<si> vsi;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using Mi = map<ll, T>;
template <typename T> using MMi = map<ll, Mi<T>>;

/*
int main() {
	printTest();
	return 0;
}
*/
//ios::sync_with_stdio(false);
//cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
vi tree;

void build(vi &arr, ll ind, ll l, ll r) {
	if (l == r) {
		tree[ind] = arr[l];
		return;
	}
	ll mid = (l + r) / 2;
	build(arr, ind * 2, l, mid);
	build(arr, ind * 2 + 1, mid + 1, r);
	tree[ind] = max(tree[ind * 2], tree[ind * 2 + 1]);
}
ll getMax(ll ind, ll tl, ll tr, ll l, ll r) {
	if (l > r)
		return 0;
	if (l == tl && r == tr)
		return tree[ind];
	ll tm = (tl + tr) / 2;
	ll a = getMax(ind * 2, tl, tm, l, min(r, tm));
	ll b = getMax(ind * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
	return max(a, b);
}

vb prim;
void er() {
	ll n = 1e6;
	prim = vb(n + 1, true);
	prim[0] = prim[1] = false;
	for (ll i = 2; i <= n; i++) {
		if (prim[i]) {
			for (ll j = i * i; j <= n; j += i) {
				prim[j] = false;
			}
		}
	}
}
vi topSort(ll v, V<si> &g) {
	vi ans;
	vb viz(g.size(),false);
	//dfs(v, g, viz, ans);
	return ans;
}
ll rast(pi &a, pi &b) {
	return abs(a.first - b.first) + abs(a.second - b.second);
}
vi z_function(string &s) {
	ll n = s.length();
	vi z(n,0);
	ll l = 0, r = 0;
	for (ll i = 1; i < n; i++) {
		if (i <= r) {
			z[i] = min(r - i + 1, z[i - l]);
		}
		while (i+z[i]<n && s[z[i]] == s[z[i]+i]) {
			z[i]++;
		}
		if (i + z[i] - 1 > r) {
			l = i;
			r = i + z[i] - 1;
		}
	}
	return z;
}
bool comp(const string &a, const string &b) {
	return a.size() < b.size();
}

void printTest() {
	freopen("output.txt", "w", stdout);
	cout << "1000 500 1000" << endl;
	for (int i = 0; i < 500; i++) {
		cout << i*2 << " " << i*2 + 1 << endl;
	}
	for (int i = 0; i < 1000; i++) {
		cout << i << " " << 1000 - i << endl;
	}
}

ll getDiam(ll v, vvi &g, vb &viz, vi &ans) {
	viz[v] = true;
	multiset<pi> m;
	ll ret = 0;
	for (ll u : g[v]) {
		if (!viz[u]) {
			ll glub = getDiam(u, g, viz, ans)+1;
			ret = max(ret, glub);
			m.insert({ glub,u });
			if (m.size() > 2) {
				m.erase(m.begin());
			}

		}
	}
	ll diam = 0;
	for (pi a : m) {
		diam += a.first;
	}
	ans[v] = diam;
	return ret;
}
void createVertx(ll v, vsi &g, vb &viz, vi &vertx) {
	vertx.push_back(v);
viz[v] = true;
for (ll u : g[v]) {
	if (!viz[u]) {
		createVertx(u, g, viz, vertx);
	}
}
}
void centry(vi &vertx, vsi g, pi &ans, vi &count) {

	spi lists;
	for (ll v : vertx) {
		lists.insert({ count[v],v });
	}

	ll rad = 0;
	while (lists.size() > 2) {
		rad++;
		si del;
		while (lists.begin()->first == 1) {
			del.insert(lists.begin()->second);
			lists.erase(lists.begin());
		}
		for (ll v : del) {
			ll u = *g[v].begin();
			pi p;
			p.first = count[u];
			p.second = u;
			lists.erase(p);
			count[u]--;
			g[u].erase(v);
			lists.insert({ count[u],u });
		}
	}
	ans.first = lists.begin()->second;
	if (lists.size() == 2) {
		rad++;
	}
	ans.second = rad;
}

pi getCentry(ll v, vsi &g, vb &viz, vi &count) {
	vi vertx;
	createVertx(v, g, viz, vertx);
	pi ans;
	centry(vertx, g, ans, count);
	return { ans.second, ans.first };
}

vi parent;
vi rang;

void make_set(int v) {
	parent[v] = v;
	rang[v] = 0;
}

int find_set(int v) {
	if (v == parent[v])
		return v;
	return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
	a = find_set(a);
	b = find_set(b);
	if (a != b) {
		parent[b] = a;
	}
}

map<pi, ll> path;
vi a;
ll getPath(ll v, ll u) {
	if (path.find({ u,v }) == path.end()) {
		return a[v] + a[u];
	}
	return min(a[v] + a[u], path[{u, v}]);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//freopen("output.txt", "r", stdin);
	ll n, m;
	cin >> n >> m;
	a = vi(n);
	ll core = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] < a[core]) {
			core = i;
		}
	}
	vvi matr(n, vi());
	for (int i = 0; i < m; i++) {
		ll x, y, c;
		cin >> x >> y >> c;
		x--; y--;
		if ((path.find({ x,y }) == path.end() && c<a[x]+a[y]) || (path.find({ x,y }) != path.end() && path[{x, y}] > c)){
			matr[x].push_back(y);
			matr[y].push_back(x);
			path[{y, x}] = c;
			path[{x, y}] = c;
		}
	}
	parent = vi(n);
	rang = vi(n);
	for (int i = 0; i < n; i++) {
		make_set(i);
	}
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		if (i == core) {
			continue;
		}
		ll path2 = getPath(core, i);
		pi minC = {core,path2};
		for (ll v : matr[i]) {
			if (v == core) {
				continue;
			}
			ll c = getPath(i, v);
			if (c < minC.second) {
				minC.second = c;
				minC.first = v;
			}
		}

		if (minC.first!=core) {
			ll v = find_set(minC.first);
			if (v == i) {
				continue;
			}
			ll p1 = getPath(core, v);
			ll p2 = getPath(core, i);
			if (p1 < p2 ){
				union_sets(v, i);
			}
			else {
				union_sets(i, v);
			}
			sum += minC.second;

			path.erase({ minC.first,i });
			path.erase({ i,minC.first });
		}
	}

	for (int i = 0; i < n; i++) {
		if (i == core) {
			continue;
		}
		if (parent[i] == i) {
			sum += getPath(core, i);
		}
	}
	cout << sum;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#define endl '\n'

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pi;
typedef pair<pi, ll> ppi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<vpi> vvpi;
typedef vector<ppi> vppi;
typedef vector<bool> vb;
typedef map<ll, ll> mii;
typedef set<pi> spi;
typedef set<ll> si;
typedef vector<si> vsi;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using Mi = map<ll, T>;
template <typename T> using MMi = map<ll, Mi<T>>;

/*
int main() {
	printTest();
	return 0;
}
*/
//ios::sync_with_stdio(false);
//cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
vi tree;

void build(vi &arr, ll ind, ll l, ll r) {
	if (l == r) {
		tree[ind] = arr[l];
		return;
	}
	ll mid = (l + r) / 2;
	build(arr, ind * 2, l, mid);
	build(arr, ind * 2 + 1, mid + 1, r);
	tree[ind] = max(tree[ind * 2], tree[ind * 2 + 1]);
}
ll getMax(ll ind, ll tl, ll tr, ll l, ll r) {
	if (l > r)
		return 0;
	if (l == tl && r == tr)
		return tree[ind];
	ll tm = (tl + tr) / 2;
	ll a = getMax(ind * 2, tl, tm, l, min(r, tm));
	ll b = getMax(ind * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
	return max(a, b);
}

vb prim;
void er() {
	ll n = 1e6;
	prim = vb(n + 1, true);
	prim[0] = prim[1] = false;
	for (ll i = 2; i <= n; i++) {
		if (prim[i]) {
			for (ll j = i * i; j <= n; j += i) {
				prim[j] = false;
			}
		}
	}
}
vi topSort(ll v, V<si> &g) {
	vi ans;
	vb viz(g.size(),false);
	//dfs(v, g, viz, ans);
	return ans;
}
ll rast(pi &a, pi &b) {
	return abs(a.first - b.first) + abs(a.second - b.second);
}
vi z_function(string &s) {
	ll n = s.length();
	vi z(n,0);
	ll l = 0, r = 0;
	for (ll i = 1; i < n; i++) {
		if (i <= r) {
			z[i] = min(r - i + 1, z[i - l]);
		}
		while (i+z[i]<n && s[z[i]] == s[z[i]+i]) {
			z[i]++;
		}
		if (i + z[i] - 1 > r) {
			l = i;
			r = i + z[i] - 1;
		}
	}
	return z;
}
bool comp(const string &a, const string &b) {
	return a.size() < b.size();
}

void printTest() {
	freopen("output.txt", "w", stdout);
	cout << "1000 500 1000" << endl;
	for (int i = 0; i < 500; i++) {
		cout << i*2 << " " << i*2 + 1 << endl;
	}
	for (int i = 0; i < 1000; i++) {
		cout << i << " " << 1000 - i << endl;
	}
}

ll getDiam(ll v, vvi &g, vb &viz, vi &ans) {
	viz[v] = true;
	multiset<pi> m;
	ll ret = 0;
	for (ll u : g[v]) {
		if (!viz[u]) {
			ll glub = getDiam(u, g, viz, ans)+1;
			ret = max(ret, glub);
			m.insert({ glub,u });
			if (m.size() > 2) {
				m.erase(m.begin());
			}

		}
	}
	ll diam = 0;
	for (pi a : m) {
		diam += a.first;
	}
	ans[v] = diam;
	return ret;
}
void createVertx(ll v, vsi &g, vb &viz, vi &vertx) {
	vertx.push_back(v);
	viz[v] = true;
	for (ll u : g[v]) {
		if (!viz[u]) {
			createVertx(u, g, viz, vertx);
		}
	}
}
void centry(vi &vertx, vsi g, pi &ans, vi &count) {

	spi lists;
	for (ll v : vertx) {
		lists.insert({ count[v],v });
	}

	ll rad = 0;
	while (lists.size() > 2) {
		rad++;
		si del;
		while (lists.begin()->first==1) {
			del.insert(lists.begin()->second);
			lists.erase(lists.begin());
		}
		for (ll v : del) {
			ll u = *g[v].begin();
			pi p;
			p.first = count[u];
			p.second = u;
			lists.erase(p);
			count[u]--;
			g[u].erase(v);
			lists.insert({ count[u],u });
		}
	}
	ans.first = lists.begin()->second;
	if (lists.size() == 2) {
		rad++;
	}
	ans.second = rad;
}

pi getCentry(ll v, vsi &g, vb &viz, vi &count) {
	vi vertx;
	createVertx(v, g, viz, vertx);
	pi ans;
	centry(vertx, g, ans, count);
	return { ans.second, ans.first };
}

vi parent;
vi rang;

void make_set(int v) {
	parent[v] = v;
	rang[v] = 0;
}

int find_set(int v) {
	if (v == parent[v])
		return v;
	return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
	a = find_set(a);
	b = find_set(b);
	if (a != b) {
		if (rang[a] < rang[b])
			swap(a, b);
		parent[b] = a;
		if (rang[a] == rang[b])
			++rang[a];
	}
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n, m;
	cin >> n >> m;
	vi a(n);
	ll core = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] < a[core]) {
			core = i;
		}
	}
	vvpi matr(n, vpi());
	for (int i = 0; i < m; i++) {
		ll x, y, c;
		cin >> x >> y >> c;
		x--; y--;
		matr[x].push_back({ y,c });
		matr[y].push_back({ x,c });
	}
	parent = vi(n);
	rang = vi(n);
	for (int i = 0; i < n; i++) {
		make_set(i);
	}
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		if (i == core) {
			continue;
		}
		ll soed = (a[i] + a[core]);
		pi minC = {core,soed};
		for (pi p : matr[i]) {
			ll v = p.first;
			ll c = p.second;
			if (c < minC.second) {
				minC.second = c;
				minC.first = v;
			}
		}
		if (minC.second!=soed) {
			if (minC.first == core) {
				sum += minC.second;
				continue;
			}
			ll v = find_set(minC.first);
			if (a[v] < a[i] || (a[v]==a[i]&&i<v)) {
				union_sets(i, v);
				sum += minC.second;
				continue;
			}
		}
		sum += soed;
	}
	cout << sum;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#define endl '\n'

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pi;
typedef pair<pi, ll> ppi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<vpi> vvpi;
typedef vector<ppi> vppi;
typedef vector<bool> vb;
typedef map<ll, ll> mii;
typedef set<pi> spi;
typedef set<ll> si;
typedef vector<si> vsi;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using Mi = map<ll, T>;
template <typename T> using MMi = map<ll, Mi<T>>;

/*
int main() {
	printTest();
	return 0;
}
*/
//ios::sync_with_stdio(false);
//cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
vi tree;

void build(vi &arr, ll ind, ll l, ll r) {
	if (l == r) {
		tree[ind] = arr[l];
		return;
	}
	ll mid = (l + r) / 2;
	build(arr, ind * 2, l, mid);
	build(arr, ind * 2 + 1, mid + 1, r);
	tree[ind] = max(tree[ind * 2], tree[ind * 2 + 1]);
}
ll getMax(ll ind, ll tl, ll tr, ll l, ll r) {
	if (l > r)
		return 0;
	if (l == tl && r == tr)
		return tree[ind];
	ll tm = (tl + tr) / 2;
	ll a = getMax(ind * 2, tl, tm, l, min(r, tm));
	ll b = getMax(ind * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
	return max(a, b);
}

vb prim;
void er() {
	ll n = 1e6;
	prim = vb(n + 1, true);
	prim[0] = prim[1] = false;
	for (ll i = 2; i <= n; i++) {
		if (prim[i]) {
			for (ll j = i * i; j <= n; j += i) {
				prim[j] = false;
			}
		}
	}
}
vi topSort(ll v, V<si> &g) {
	vi ans;
	vb viz(g.size(),false);
	//dfs(v, g, viz, ans);
	return ans;
}
ll rast(pi &a, pi &b) {
	return abs(a.first - b.first) + abs(a.second - b.second);
}
vi z_function(string &s) {
	ll n = s.length();
	vi z(n,0);
	ll l = 0, r = 0;
	for (ll i = 1; i < n; i++) {
		if (i <= r) {
			z[i] = min(r - i + 1, z[i - l]);
		}
		while (i+z[i]<n && s[z[i]] == s[z[i]+i]) {
			z[i]++;
		}
		if (i + z[i] - 1 > r) {
			l = i;
			r = i + z[i] - 1;
		}
	}
	return z;
}
bool comp(const string &a, const string &b) {
	return a.size() < b.size();
}

void printTest() {
	freopen("output.txt", "w", stdout);
	cout << "1000 500 1000" << endl;
	for (int i = 0; i < 500; i++) {
		cout << i*2 << " " << i*2 + 1 << endl;
	}
	for (int i = 0; i < 1000; i++) {
		cout << i << " " << 1000 - i << endl;
	}
}

ll getDiam(ll v, vvi &g, vb &viz, vi &ans) {
	viz[v] = true;
	multiset<pi> m;
	ll ret = 0;
	for (ll u : g[v]) {
		if (!viz[u]) {
			ll glub = getDiam(u, g, viz, ans)+1;
			ret = max(ret, glub);
			m.insert({ glub,u });
			if (m.size() > 2) {
				m.erase(m.begin());
			}

		}
	}
	ll diam = 0;
	for (pi a : m) {
		diam += a.first;
	}
	ans[v] = diam;
	return ret;
}
void createVertx(ll v, vsi &g, vb &viz, vi &vertx) {
	vertx.push_back(v);
	viz[v] = true;
	for (ll u : g[v]) {
		if (!viz[u]) {
			createVertx(u, g, viz, vertx);
		}
	}
}
void centry(vi &vertx, vsi g, pi &ans, vi &count) {

	spi lists;
	for (ll v : vertx) {
		lists.insert({ count[v],v });
	}

	ll rad = 0;
	while (lists.size() > 2) {
		rad++;
		si del;
		while (lists.begin()->first==1) {
			del.insert(lists.begin()->second);
			lists.erase(lists.begin());
		}
		for (ll v : del) {
			ll u = *g[v].begin();
			pi p;
			p.first = count[u];
			p.second = u;
			lists.erase(p);
			count[u]--;
			g[u].erase(v);
			lists.insert({ count[u],u });
		}
	}
	ans.first = lists.begin()->second;
	if (lists.size() == 2) {
		rad++;
	}
	ans.second = rad;
}

pi getCentry(ll v, vsi &g, vb &viz, vi &count) {
	vi vertx;
	createVertx(v, g, viz, vertx);
	pi ans;
	centry(vertx, g, ans, count);
	return { ans.second, ans.first };
}

vi parent;
vi rang;

void make_set(int v) {
	parent[v] = v;
	rang[v] = 0;
}

int find_set(int v) {
	if (v == parent[v])
		return v;
	return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
	a = find_set(a);
	b = find_set(b);
	if (a != b) {
		parent[b] = a;
	}
}

map<pi,ll> path;
vi a;
ll getPath(ll v, ll u) {
	if (path.find({ u,v }) == path.end()) {
		return a[v] + a[u];
	}
	return min(a[v] + a[u], path[{u, v}]);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n, m;
	cin >> n >> m;
	a = vi(n);
	ll core = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] < a[core]) {
			core = i;
		}
	}
	vvpi matr(n, vpi());
	for (int i = 0; i < m; i++) {
		ll x, y, c;
		cin >> x >> y >> c;
		x--; y--;
		matr[x].push_back({ y,c });
		matr[y].push_back({ x,c });
		path[{y, x}] = c;
		path[{x, y}] = c;
	}
	parent = vi(n);
	rang = vi(n);
	for (int i = 0; i < n; i++) {
		make_set(i);
	}
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		if (i == core) {
			continue;
		}
		ll soed = (a[i] + a[core]);
		pi minC = {core,soed};
		for (pi p : matr[i]) {
			ll v = p.first;
			ll c = p.second;
			if (c < minC.second) {
				minC.second = c;
				minC.first = v;
			}
		}
		if (minC.second!=soed) {
			if (minC.first == core) {
				sum += minC.second;
				continue;
			}
			ll v = find_set(minC.first);
			ll p1 = getPath(core, v);
			ll p2 = getPath(core, i);
			if (p1 < p2 || (p1==p2 && i<v )) {
				union_sets(v, i);
				sum += minC.second;
				continue;
			}
		}
		sum += soed;
	}
	cout << sum;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#define endl '\n'

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pi;
typedef pair<pi, ll> ppi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<vpi> vvpi;
typedef vector<ppi> vppi;
typedef vector<bool> vb;
typedef map<ll, ll> mii;
typedef set<pi> spi;
typedef set<ll> si;
typedef vector<si> vsi;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using Mi = map<ll, T>;
template <typename T> using MMi = map<ll, Mi<T>>;

/*
int main() {
	printTest();
	return 0;
}
*/
//ios::sync_with_stdio(false);
//cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
vi tree;

void build(vi &arr, ll ind, ll l, ll r) {
	if (l == r) {
		tree[ind] = arr[l];
		return;
	}
	ll mid = (l + r) / 2;
	build(arr, ind * 2, l, mid);
	build(arr, ind * 2 + 1, mid + 1, r);
	tree[ind] = max(tree[ind * 2], tree[ind * 2 + 1]);
}
ll getMax(ll ind, ll tl, ll tr, ll l, ll r) {
	if (l > r)
		return 0;
	if (l == tl && r == tr)
		return tree[ind];
	ll tm = (tl + tr) / 2;
	ll a = getMax(ind * 2, tl, tm, l, min(r, tm));
	ll b = getMax(ind * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
	return max(a, b);
}

vb prim;
void er() {
	ll n = 1e6;
	prim = vb(n + 1, true);
	prim[0] = prim[1] = false;
	for (ll i = 2; i <= n; i++) {
		if (prim[i]) {
			for (ll j = i * i; j <= n; j += i) {
				prim[j] = false;
			}
		}
	}
}
vi topSort(ll v, V<si> &g) {
	vi ans;
	vb viz(g.size(),false);
	//dfs(v, g, viz, ans);
	return ans;
}
ll rast(pi &a, pi &b) {
	return abs(a.first - b.first) + abs(a.second - b.second);
}
vi z_function(string &s) {
	ll n = s.length();
	vi z(n,0);
	ll l = 0, r = 0;
	for (ll i = 1; i < n; i++) {
		if (i <= r) {
			z[i] = min(r - i + 1, z[i - l]);
		}
		while (i+z[i]<n && s[z[i]] == s[z[i]+i]) {
			z[i]++;
		}
		if (i + z[i] - 1 > r) {
			l = i;
			r = i + z[i] - 1;
		}
	}
	return z;
}
bool comp(const string &a, const string &b) {
	return a.size() < b.size();
}

void printTest() {
	freopen("output.txt", "w", stdout);
	cout << "1000 500 1000" << endl;
	for (int i = 0; i < 500; i++) {
		cout << i*2 << " " << i*2 + 1 << endl;
	}
	for (int i = 0; i < 1000; i++) {
		cout << i << " " << 1000 - i << endl;
	}
}

ll getDiam(ll v, vvi &g, vb &viz, vi &ans) {
	viz[v] = true;
	multiset<pi> m;
	ll ret = 0;
	for (ll u : g[v]) {
		if (!viz[u]) {
			ll glub = getDiam(u, g, viz, ans)+1;
			ret = max(ret, glub);
			m.insert({ glub,u });
			if (m.size() > 2) {
				m.erase(m.begin());
			}

		}
	}
	ll diam = 0;
	for (pi a : m) {
		diam += a.first;
	}
	ans[v] = diam;
	return ret;
}
void createVertx(ll v, vsi &g, vb &viz, vi &vertx) {
	vertx.push_back(v);
	viz[v] = true;
	for (ll u : g[v]) {
		if (!viz[u]) {
			createVertx(u, g, viz, vertx);
		}
	}
}
void centry(vi &vertx, vsi g, pi &ans, vi &count) {

	spi lists;
	for (ll v : vertx) {
		lists.insert({ count[v],v });
	}

	ll rad = 0;
	while (lists.size() > 2) {
		rad++;
		si del;
		while (lists.begin()->first==1) {
			del.insert(lists.begin()->second);
			lists.erase(lists.begin());
		}
		for (ll v : del) {
			ll u = *g[v].begin();
			pi p;
			p.first = count[u];
			p.second = u;
			lists.erase(p);
			count[u]--;
			g[u].erase(v);
			lists.insert({ count[u],u });
		}
	}
	ans.first = lists.begin()->second;
	if (lists.size() == 2) {
		rad++;
	}
	ans.second = rad;
}

pi getCentry(ll v, vsi &g, vb &viz, vi &count) {
	vi vertx;
	createVertx(v, g, viz, vertx);
	pi ans;
	centry(vertx, g, ans, count);
	return { ans.second, ans.first };
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n, m;
	cin >> n >> m;
	vi a(n);
	ll core = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] < a[core]) {
			core = i;
		}
	}
	vvpi matr(n, vpi());
	for (int i = 0; i < m; i++) {
		ll x, y, c;
		cin >> x >> y >> c;
		x--; y--;
		matr[x].push_back({ y,c });
		matr[y].push_back({ x,c });
	}
	vi parent(n);
	for (int i = 0; i < n; i++) {
		parent[i] = i;
	}
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		if (i == core) {
			continue;
		}
		ll soed = (a[i] + a[core]);
		pi minC = {core,soed};
		for (pi p : matr[i]) {
			ll v = p.first;
			ll c = p.second;
			if (c < minC.second) {
				minC.second = c;
				minC.first = v;
			}
		}
		if (minC.second!=soed) {
			if (minC.first == core) {
				sum += minC.second;
				continue;
			}
			ll v = parent[minC.first];
			if (a[v] < a[i] || (a[v]==a[i]&&i<v)) {
				parent[i] = parent[v];
				sum += minC.second;
				continue;
			}
		}
		sum += soed;
	}
	cout << sum;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#define endl '\n'

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pi;
typedef pair<pi, ll> ppi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<vpi> vvpi;
typedef vector<ppi> vppi;
typedef vector<bool> vb;
typedef map<ll, ll> mii;
typedef set<pi> spi;
typedef set<ll> si;
typedef vector<si> vsi;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using Mi = map<ll, T>;
template <typename T> using MMi = map<ll, Mi<T>>;

/*
int main() {
	printTest();
	return 0;
}
*/
//ios::sync_with_stdio(false);
//cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
vi tree;

void build(vi &arr, ll ind, ll l, ll r) {
	if (l == r) {
		tree[ind] = arr[l];
		return;
	}
	ll mid = (l + r) / 2;
	build(arr, ind * 2, l, mid);
	build(arr, ind * 2 + 1, mid + 1, r);
	tree[ind] = max(tree[ind * 2], tree[ind * 2 + 1]);
}
ll getMax(ll ind, ll tl, ll tr, ll l, ll r) {
	if (l > r)
		return 0;
	if (l == tl && r == tr)
		return tree[ind];
	ll tm = (tl + tr) / 2;
	ll a = getMax(ind * 2, tl, tm, l, min(r, tm));
	ll b = getMax(ind * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
	return max(a, b);
}

vb prim;
void er() {
	ll n = 1e6;
	prim = vb(n + 1, true);
	prim[0] = prim[1] = false;
	for (ll i = 2; i <= n; i++) {
		if (prim[i]) {
			for (ll j = i * i; j <= n; j += i) {
				prim[j] = false;
			}
		}
	}
}
vi topSort(ll v, V<si> &g) {
	vi ans;
	vb viz(g.size(),false);
	//dfs(v, g, viz, ans);
	return ans;
}
ll rast(pi &a, pi &b) {
	return abs(a.first - b.first) + abs(a.second - b.second);
}
vi z_function(string &s) {
	ll n = s.length();
	vi z(n,0);
	ll l = 0, r = 0;
	for (ll i = 1; i < n; i++) {
		if (i <= r) {
			z[i] = min(r - i + 1, z[i - l]);
		}
		while (i+z[i]<n && s[z[i]] == s[z[i]+i]) {
			z[i]++;
		}
		if (i + z[i] - 1 > r) {
			l = i;
			r = i + z[i] - 1;
		}
	}
	return z;
}
bool comp(const string &a, const string &b) {
	return a.size() < b.size();
}

void printTest() {
	freopen("output.txt", "w", stdout);
	cout << "1000 500 1000" << endl;
	for (int i = 0; i < 500; i++) {
		cout << i*2 << " " << i*2 + 1 << endl;
	}
	for (int i = 0; i < 1000; i++) {
		cout << i << " " << 1000 - i << endl;
	}
}

ll getDiam(ll v, vvi &g, vb &viz, vi &ans) {
	viz[v] = true;
	multiset<pi> m;
	ll ret = 0;
	for (ll u : g[v]) {
		if (!viz[u]) {
			ll glub = getDiam(u, g, viz, ans)+1;
			ret = max(ret, glub);
			m.insert({ glub,u });
			if (m.size() > 2) {
				m.erase(m.begin());
			}

		}
	}
	ll diam = 0;
	for (pi a : m) {
		diam += a.first;
	}
	ans[v] = diam;
	return ret;
}
void createVertx(ll v, vsi &g, vb &viz, vi &vertx) {
	vertx.push_back(v);
viz[v] = true;
for (ll u : g[v]) {
	if (!viz[u]) {
		createVertx(u, g, viz, vertx);
	}
}
}
void centry(vi &vertx, vsi g, pi &ans, vi &count) {

	spi lists;
	for (ll v : vertx) {
		lists.insert({ count[v],v });
	}

	ll rad = 0;
	while (lists.size() > 2) {
		rad++;
		si del;
		while (lists.begin()->first == 1) {
			del.insert(lists.begin()->second);
			lists.erase(lists.begin());
		}
		for (ll v : del) {
			ll u = *g[v].begin();
			pi p;
			p.first = count[u];
			p.second = u;
			lists.erase(p);
			count[u]--;
			g[u].erase(v);
			lists.insert({ count[u],u });
		}
	}
	ans.first = lists.begin()->second;
	if (lists.size() == 2) {
		rad++;
	}
	ans.second = rad;
}

pi getCentry(ll v, vsi &g, vb &viz, vi &count) {
	vi vertx;
	createVertx(v, g, viz, vertx);
	pi ans;
	centry(vertx, g, ans, count);
	return { ans.second, ans.first };
}

vi parent;
vi rang;

void make_set(int v) {
	parent[v] = v;
	rang[v] = 0;
}

int find_set(int v) {
	if (v == parent[v])
		return v;
	return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
	a = find_set(a);
	b = find_set(b);
	if (a != b) {
		parent[b] = a;
	}
}

map<pi, ll> path;
vi a;
ll getPath(ll v, ll u) {
	if (path.find({ u,v }) == path.end()) {
		return a[v] + a[u];
	}
	return min(a[v] + a[u], path[{u, v}]);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//freopen("output.txt", "r", stdin);
	ll n, m;
	cin >> n >> m;
	a = vi(n);
	ll core = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] < a[core]) {
			core = i;
		}
	}
	vvi matr(n, vi());
	for (int i = 0; i < m; i++) {
		ll x, y, c;
		cin >> x >> y >> c;
		x--; y--;
		if ((path.find({ x,y }) == path.end() && c<a[x]+a[y]) || (path.find({ x,y }) != path.end() && path[{x, y}] < c)){
			matr[x].push_back(y);
			matr[y].push_back(x);
			path[{y, x}] = c;
			path[{x, y}] = c;
		}
	}
	parent = vi(n);
	rang = vi(n);
	for (int i = 0; i < n; i++) {
		make_set(i);
	}
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		if (i == core) {
			continue;
		}
		ll path2 = getPath(core, i);
		pi minC = {core,path2};
		for (ll v : matr[i]) {
			if (v == core) {
				continue;
			}
			ll c = getPath(i, v);
			if (c < minC.second) {
				minC.second = c;
				minC.first = v;
			}
		}

		if (minC.first!=core) {
			ll v = find_set(minC.first);
			if (v == i) {
				continue;
			}
			ll p1 = getPath(core, v);
			ll p2 = getPath(core, i);
			if (p1 < p2 ){
				union_sets(v, i);
				sum += minC.second;
			}
			else {
				union_sets(i, v);
			}

		}
	}
	for (int i = 0; i < n; i++) {
		if (i == core) {
			continue;
		}
		if (parent[i] == i) {
			sum += getPath(core, i);
		}
	}
	cout << sum;
	return 0;
}