/**
  * @brief atcoder
  * @author yao
  */
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <climits>
#define ft first
#define sd second
#ifdef DBG
#   define dbg_pri(x...) fprintf(stderr,x)
#else
#   define dbg_pri(x...) 0
#   define NDEBUG
#endif //DBG
#include <cassert>

typedef unsigned int uint;
typedef long long int lli;
typedef unsigned long long int ulli;

#define N 131072

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

int lea[N];
lli w[N];
int cnt[N];

int getlea(int k)
{
    if(lea[k] != lea[lea[k]]) lea[k] = getlea(lea[k]);
    return lea[k];
}

int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    for(int i=0;i<n;++i) lea[i] = i;
    for(int i=0;i<n;++i) scanf("%lld", &w[i]);
    for(int i=0;i<m;++i) scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w), --e[i].u, --e[i].v;
    std::sort(e,e+m,[](Edge a, Edge b){return a.w<b.w;});
    for(int i=0;i<m;++i)
    {
        int u = getlea(e[i].u), v = getlea(e[i].v);
        if(u!=v)
        {
            lea[v] = u;
            w[u] += w[v];
            cnt[u] += cnt[v];
        }
        if(w[u] < e[i].w) ++cnt[u];
        else cnt[u] = 0;
    }
    int ans = 0;
    for(int i=0;i<n;++i)if(lea[i] == i) ans += cnt[i];
    printf("%d\n", ans);
    return 0;
}
