#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> pip;
typedef long long LL;
const int MAXN = 123456;
int par[MAXN];
LL gp[MAXN], postp[MAXN];
bool visit[MAXN];

int find(int x) {
    return x == par[x] ? x : (par[x] = find(par[x]));
}

void merge(int x, int y) {
     x = find(x);
     y = find(y);
     if (x == y) return;
     par[y] = x;
     gp[x] += gp[y];
     postp[x] += postp[y];
}

int main() {
    int N, M;
    scanf("%d %d", &N, &M);
    for (int i = 1; i <= N; i++) {
        par[i] = i;
        scanf("%lld", &gp[i]);
    }
    vector<pip> edges;
    for (int i = 0; i < M; i++) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        edges.push_back(make_pair(c, make_pair(a, b)));
    }
    sort(edges.begin(), edges.end());
    for (auto i : edges) {
        int c = i.first, a = i.second.first, b = i.second.second;
        merge(a, b);
        int cur = find(a);
        if (c > gp[cur]) postp[cur]++;
        else postp[cur] = 0;
    }
    LL ans = 0;
    for (int i = 1; i <= N; i++) {
        int cur = find(i);
        if (visit[cur]) continue;
        visit[cur] = 1;
        ans += postp[cur];
    }
    printf("%lld\n", ans);
    return 0;
}
