#include<cstdio>
#include<vector>
#include<algorithm>
#include<tuple>
using namespace std;
const int MAX = 100000 + 10;
vector<tuple<int,int,long long>> v;

long long siz[MAX];

int p[MAX];
long long rec[MAX];
int cnt[MAX];

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

bool cmp(tuple<int,int,int> a, tuple<int,int,int> b) {
    return get<2>(a) < get<2>(b);
}

int main () {
    int n, m;
    scanf("%d %d", &n, &m);
    for(int i = 0 ; i < n ; i++) {
        scanf("%lld", &rec[i]);
    }
    for(int i = 0 ; i < m ; i++) {
        int x, y;
        long long val;
        scanf("%d %d %lld", &x, &y, &val);
        x--, y--;
        v.push_back(make_tuple(x,y,val));
    }
    sort(v.begin(), v.end(), cmp);
    for(int i = 0 ; i < n ; i++) {
        p[i] = i;
        siz[i] = rec[i];
    }
    int ans = m;
    for(auto emt: v) {
        int x = get<0>(emt);
        int y = get<1>(emt);
        long long val = get<2>(emt);
        int px = find(x);
        int py = find(y);
        if(px != py) {
            siz[px] += siz[py];
            cnt[px] += cnt[py];
            p[py] = px;
        }
        cnt[px]++;
        if(siz[px] >= val) {
            ans -= cnt[px];
            cnt[px] = 0;
        }
    }
    printf("%d\n", ans);
    return 0;
}
