#include <bits/stdc++.h>

#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

struct Edge {
    int from, to;
    ll cost;
    Edge(int f, int t, ll c): from(f), to(t), cost(c) {}
    bool operator<(const Edge &e) const {
        return cost < e.cost;
    }
};

ll nodes[100001];
vector<Edge> edges;
vector< pair<int, ll> > G[100001];
map<Pii, int> used;
set<Pii> ans;

class UnionFind {
    public:
    int n;
    vector<int> par, rank;
    vector<ll> nodes_cost, max_edge_cost;

    UnionFind(int n) {
        for(int i=0;i<n;++i){
            par.push_back(i);
            rank.push_back(0);
            nodes_cost.push_back(nodes[i]);
            max_edge_cost.push_back(0);
        }
    }

    int find(int x) {
        if(par[x] == x) {
            return x;
        } else {
            par[x] = find(par[x]);
            nodes_cost[x] = max(
                nodes_cost[x],
                nodes_cost[par[x]]
            );
            max_edge_cost[x] = max(
                max_edge_cost[x], 
                max_edge_cost[par[x]]
            );
            return par[x];
        }
    }

    ll get_nodes_cost(int x) {
        return nodes_cost[find(x)];
    }

    ll get_max_edge_cost(int x) {
        return max_edge_cost[find(x)];
    }

    void unite(Edge e) {
        int x = e.from, y = e.to;
        x = find(x);
        y = find(y);

        
        ll mec = max(
            {get_max_edge_cost(x), get_max_edge_cost(y), e.cost}
        );
        max_edge_cost[x] = mec;
        max_edge_cost[y] = mec;
        if(x == y) {
            return;
        }

        
        nodes_cost[y] += nodes_cost[x];
        nodes_cost[x] = nodes_cost[y];
        if(rank[x] < rank[y]){
            par[x] = y;
        }else{
            par[y] = x;
            if(rank[x] == rank[y]) rank[x]++;
        }
        return;
    }

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

void dfs(int node, ll c) {
    for(pair<int, ll> p: G[node]) {
        int a = min(node, p.first);
        int b = max(node, p.first);
        if(used[Pii(a, b)] || p.second > c) continue;
        used[Pii(a, b)] = 1;
        ans.emplace(a, b);
        dfs(p.first, c);
    }
}

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n, m, a, b;
    ll c;
    cin >> n >> m;
    for(int i=0;i<n;++i) cin >> nodes[i];
    for(int i=0;i<m;++i) {
        cin >> a >> b >> c;
        edges.push_back(Edge(a-1, b-1, c));
        G[a-1].emplace_back(b-1, c);
        G[b-1].emplace_back(a-1, c);
    }
    sort(all(edges));

    UnionFind uf = UnionFind(n);
    vector<Edge> candidates; // 連結成分内最大コストの辺の候補たち
    for(int i=0;i<m;++i) {
        Edge e = edges[i];
        uf.unite(e);
        if(uf.get_nodes_cost(e.from) >= e.cost) {
            candidates.push_back(e);
        }
    }

    for(int i=candidates.size()-1;i>=0;--i) {
        a = min(candidates[i].from, candidates[i].to);
        b = max(candidates[i].from, candidates[i].to);
        if(used[Pii(a, b)]) continue;
        used[Pii(a, b)] = 1;
        ans.emplace(a, b);
        dfs(a, candidates[i].cost);
        dfs(b, candidates[i].cost);
    }

    cout << m-ans.size() << endl;
}


Measured memory_bytes: 35696