#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], sum[N], mx[N], kek[N];
int bad;

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

void unite(int v, int u, int weight) {
    v = getRoot(v), u = getRoot(u);
    if (v == u) {
        mx[v] = max(mx[v], weight);
        if (weight > sum[v]) {
            kek[v]++;
            bad++;
        }
        return;
    }
    p[u] = v;
    sum[v] += sum[u];
    mx[v] = max({ mx[v], mx[u], weight });
    bad -= kek[v] + kek[u];
    if (mx[v] > sum[v]) {
        kek[v] += kek[u] + 1;
    } else {
        kek[v] = 0;
    }
    bad += kek[v];
}

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 >> sum[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 = m;
    int it = 0;
    for (auto edge : edges) {
        it++;
        unite(edge.u, edge.v, edge.w);
        ans = min(ans, m - it + bad);
    }

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