#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
const int N = 1e5 + 10;
int x[N], fa[N], id[N];
LL sum[N];
int ls[N], rs[N], flag[N], ok[N];

struct Edge{ 
    int u, v, w;
} e[N];

bool cmp(Edge &x, Edge &y) {
    return x.w < y.w;
}

int find(int x) {
    if (fa[x] == x) return x;
    else return fa[x] = find(fa[x]);
}

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) scanf("%d", x + i);
    for (int i = 1; i <= m; i++) {
        int a, b, y;
        scanf("%d%d%d", &a, &b, &y);
        e[i] = {a, b, y};
    }
    sort(e + 1, e + m + 1, cmp);
    for (int i = 1; i <= n; i++) fa[i] = i, sum[i] = x[i];
    for (int i = 1; i <= m; i++) {
        int x = e[i].u, y = e[i].v;
        x = find(x), y = find(y);
        ls[i] = id[x];
        rs[i] = id[y];
        id[x] = i;
        if (x != y) {
            sum[x] += sum[y];
            fa[y] = x;
        }
        flag[i] = e[i].w > sum[x];
    }
    int ans = 0;
    for (int i = m; i >= 1; i--) {
        if (!ok[i] && flag[i]) ans += 1;
        if (!flag[i]) ok[i] = 1;
        if (ok[i]) {
            ok[ls[i]] = ok[rs[i]] = 1;
        }
    }
    printf("%d\n", ans);
    return 0;
}
