// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

// Union-Find 木 (Verified: AtCoder Typical Contest 001 B)
struct UnionFind {
private:
    const int n;
    int __size;
public:
    vector<int> uf, pot;
    // 初期化 UnionFind uni(n) のように宣言すれば良い
    UnionFind(int _n, vector<int> pot_) : n(_n), __size(_n), uf(_n, -1), pot(pot_) {}
    // find (木の根を求める)
    int find(int x) {return (uf[x] < 0) ? x : uf[x] = find(uf[x]);}
    // x と y が同じ集合に属するかどうか
    bool same(int x, int y) {return find(x) == find(y);}
    // x が属する集合の要素数
    int size(int x) {return -uf[find(x)];}
    // 集合はいくつあるか
    int size()      {return __size;}
    // x と y の属する集合を併合
    void unite(int x, int y) {
        x = find(x); y = find(y);
        if(x == y) return;
        __size--;
        if(uf[y] < uf[x]) swap(x, y);
        uf[x] += uf[y]; pot[x] += pot[y]; uf[y] = x;
    }
};

int N, M;
using Graph = vector< vector< pair<int, int> > >;
signed main() {
    cin >> N >> M;

    vector<int> X(N);
    for(int i=0; i<N; i++) {
        cin >> X[i];
    }

    Graph G(N);
    vector< tuple<int, int, int, int> > edges;
    for(int i=0; i<M; i++) {
        int u, v, w; cin >> u >> v >> w;
        u--; v--;
        G[u].emplace_back(v, w);
        G[v].emplace_back(u, w);
        edges.emplace_back(w, u, v, u);
    }
    sort(edges.begin(), edges.end());

    UnionFind uf(N, X);
    int use_cnt = 0;

    // 訪れた連結成分をメモる
    vector< tuple<int, int, int> > rec;
    vector<int> used(N);
    for(int i=0; i<M; i++) {
        int u, v, w, idx; tie(w, u, v, idx) = edges[i];
        uf.unite(u, v);
        bool f = (w <= uf.pot[uf.find(u)]);
        if(f) rec.emplace_back(w, u, v);
    }

    sort(rec.rbegin(), rec.rend());
    set< pair<int, int> > S;
    for(auto x : rec) {
        /*
        for(int i=0; i<N; i++) {
            for(auto e : G[i]) {
                int u = i, v = e.first, w = e.second;
                fprintf(stderr, "# u = %lld, v = %lld, w = %lld\n", u, v, w);
            }
        }
        cerr << endl;
        */

        int w, u, v; tie(w, u, v) = x;
        if(u > v) swap(u, v);
        // fprintf(stderr, "rec: (%lld, %lld), cost = %lld\n", u, v, w);
        if(S.count(make_pair(u, v))) continue;
        
        queue<int> que;
        que.push(u); que.push(v);
        while(que.size()) {
            int p = que.front(); que.pop();
            for(auto e : G[p]) {
                int fr = p, to = e.first, cost = e.second;
                if(fr > to) swap(fr, to);
                if(S.count(make_pair(fr, to))) continue;
                if(w < cost) continue;
                if(uf.find(fr) != uf.find(to)) continue;

                // fprintf(stderr, "emplace %lld, %lld, w = %lld, cost = %lld\n", fr, to, w, cost);
                S.emplace(fr, to);
                use_cnt++;
                if(p != fr) que.push(fr);
                if(p != to) que.push(to);
            }
        }
    }

    int ans = M - use_cnt;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 23020