#include <iostream>
#include <string>
#include <functional>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <algorithm>
#include <deque>

using namespace std;

const int N = 200000;

using i64 = long long;

int n, m;
i64 v[N];

struct Edge {
    int x, y;
    i64 v;
    void read() {
        scanf("%d%d%lld", &x, &y, &v);
    }
    int operator<(const Edge &o) const {
        return v < o.v;
    }
} e[N];

int f[N], inv[N];
i64 totv[N];

int getf(int x) {
    if (f[x] == x) return x;
    int tmp = getf(f[x]);
    return f[x] = tmp;
}

void log() {
    for (int i = 1; i <= n; i++) {
        printf("[i = %d] fa = %d, totv = %lld, inv = %d\n", i, f[i], totv[i], inv[i]);
    }
    cout << "=========\n";
}

int main() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) scanf("%lld", v + i);
    for (int i = 0; i < m; i++) e[i].read();
    sort(e, e + m);
    for (int i = 1; i <= n; i++) {
        f[i] = i;
        totv[i] = v[i];
        inv[i] = 0;
    }
    // log();
    for (int i = 0; i < m; i++) {
        int a = getf(e[i].x), b = getf(e[i].y);
        if (a == b) {
            if (e[i].v > totv[a]) inv[a]++;
            continue;
        }
        f[a] = b;
        totv[b] += totv[a];
        if (totv[b] >= e[i].v) {
            inv[b] = 0;
        } else {
            inv[b] += inv[a] + 1;
        }
        // log();
    }
    cout << inv[getf(1)] << endl;
    return 0;
}