#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class UnionFind {
    vector<int> p;//p[i]はiの属する組織
public:
    UnionFind(int n) {
        p = vector<int>(n);
        for (int i = 0; i < n; i++) {
            p[i] = i;
        }
        return;
    }

/* xの属する集合を返す */
    int find(int x) {
        if (p[x] == x) return x;
        return p[x] = find(p[x]);
    }

/* yにxを統合する */
    void unite(int x, int y) {
        p[find(x)] = p[find(y)];
    }

/* xとyが属する集合が同じかを判定する */
    bool same(int x, int y) {
        return find(x) == find(y);
    }

};

class Solve {
public:
    int N, M;

    vector<int> X;
    vector<vector<pair<int, ll>>> G;
    vector<tuple<ll, int, int>> edges;

    void input() {
        cin >> N >> M;
        X.resize(N);
        G.resize(N);

        for (int i = 0; i < N; ++i) {
            cin >> X[i];
        }
        for (int i = 0; i < M; ++i) {
            int a, b;
            ll y;
            cin >> a >> b >> y;
            a--, b--;
            G[a].emplace_back(b, y);
            G[b].emplace_back(a, y);
            edges.emplace_back(y, a, b);
        }
    }

    set<tuple<ll, int, int>> used; //使用済みの辺

    void dfs(int v, ll c, int p = -1) {
        for (auto e : G[v]) {
            if (e.first == p) continue;

            ll y = e.second;
            int a = e.first;
            int b = v;
            tuple<ll, int, int> edge(y, a, b);
            tuple<ll, int, int> redge(y, b, a);
            if (y > c) continue;
            if (used.count(edge)) continue;
            if (used.count(redge)) continue;

            used.insert(edge);
            used.insert(redge);
            dfs(a, c, v);
        }
    }

    void solve() {
        input();

        sort(all(edges));
        UnionFind uf(N);


        vector<tuple<ll, int, int>> kouho;
        vector<ll> gweight(N);
        for (int i = 0; i < N; ++i) {
            gweight[i] = X[i];
        }
        for (auto e : edges) {
            ll y = get<0>(e);
            int a = get<1>(e);
            int b = get<2>(e);
            if (!uf.same(a, b)) {
                gweight[uf.find(a)] += gweight[uf.find(b)];
                gweight[uf.find(b)] = gweight[uf.find(a)];
                uf.unite(a, b);
            }
            if (gweight[uf.find(a)] >= y) {
                kouho.emplace_back(y, a, b);
            }
        }

        for (auto it = kouho.rbegin(); it != kouho.rend(); it++) {
            ll y = get<0>(*it);
            int a = get<1>(*it);
            int b = get<2>(*it);


            if (!used.count(*it)) {
                used.insert(*it);
                used.insert(tuple<ll, int, int>(y, b, a));
                dfs(a, y);
                dfs(b, y);

            }
        }

        int ans = M - used.size() / 2;
        cout << ans << endl;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 35568