#include <bits/stdc++.h>

using namespace std;

using ll = long long;

struct Edge {
    int u, v, w;
};

const int N = 1e5 + 5;

int p[N], sz[N];

int getRoot(int v) {
    return v == p[v] ? v : p[v] = getRoot(p[v]);
}

void unite(int v, int u) {
    v = getRoot(v), u = getRoot(u);
    if (v == u) {
        return;
    }
    p[u] = v;
    sz[v] += sz[u];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, m;
    cin >> n >> m;
    iota(p, p + n, 0);
    for (int i = 0; i < n; i++) {
        cin >> sz[i];
    }
    vector<Edge> edges(m);
    for (int i = 0; i < m; i++) {
        cin >> edges[i].u >> edges[i].v >> edges[i].w;
        edges[i].u--;
        edges[i].v--;
    }
    sort(edges.begin(), edges.end(), [](auto& a, auto& b) {
        return a.w < b.w;
    });
    
    int ans = 0;
    vector<Edge> badEdges;
    int it = 0;
    for (auto edge : edges) {
        it++;
        unite(edge.u, edge.v);
        if (edge.w > sz[getRoot(edge.u)]) {
            badEdges.push_back(edge);
        }
        while (!badEdges.empty()) {
            Edge cur = badEdges.back();
            if (cur.w <= sz[getRoot(cur.u)]) {
                badEdges.pop_back();
            } else {
                break;
            }
        }
        if (badEdges.empty()) {
            ans = it;
        }
    }

    cout << m - ans << endl;
    return 0;
}