#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned ui;
typedef unsigned long long ul;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef pair<bool, bool> pbb;
typedef vector<int> vi;
#define pb push_back
#define fi first
#define se second
#define mid ((l + r) >> 1)
#define ls (i << 1)
#define rs (i << 1 | 1)
#define enum(i, j, k) for(int i = j; i <= k; i ++)
#define open(i, j, k)  for(int i = j; i <  k; i ++)
#define dec(i, j, k)  for(int i = j; i >= k; i --)
#define ae(x) for(node *p = h[x]; p; p = p->nxt)
template <class T> bool chkmin(T &x, T y)
{ return y < x ? x = y , true : false; }
template <class T> bool chkmax(T &x, T y)
{ return y > x ? x = y , true : false; }
int _()
{
    int ret = 0; bool f = true; char ch = getchar();
    while(!isdigit(ch)) { if(ch == '-') f = false; ch = getchar(); }
    do { ret = ret * 10 + ch - '0'; ch = getchar(); } while(isdigit(ch));
}
void _(int x)
{
    if(x < 10) { putchar(x + '0'); return ; }
    _(x / 10); putchar(x % 10 + '0');
}
void __init()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(16);
    srand(time(0) ^ ui(ul(new char)));
}
/* default code ends here */
#define maxn 100100
int n, m;
int a[maxn];
struct ed
{
    int u, v, w;
    void input()
    {
        cin >> u >> v >> w;
    }
    bool operator < (ed p) const
    {
        return w < p.w;
    }
} pool[maxn];
int fa[maxn];
int getfa(int x)
{
    return fa[x] == x ? x : fa[x] = getfa(fa[x]);
}
bool merge(int x, int y)
{
    int f1 = getfa(x), f2 = getfa(y);
    // //cerr << "M : " << x << ' ' << y << ' ' << f1 << ' ' << f2 << endl;
    return f1 == f2 ? false : (fa[f1] = f2 , true);
}
struct node
{
    int v;
    node *nxt;
} e[2 * maxn], *h[maxn];
int z;
void adde(int u, int v)
{
    e[++z] = (node){v, h[u]};
    h[u] = &e[z];
}
void addrev(int u, int v)
{
    adde(u, v);
    adde(v, u);
}
stack<ed> sta;
int col[maxn], tot;
ll sum[maxn];
bool isbigger(pii s1, pii s2)
{
    //cerr << "beg" << endl;
    queue<pii> q1, q2;
    q1.push(s1);
    q2.push(s2);
    while(!q1.empty())
    {
        if(q2.empty())
        {
            //cerr << "geb" << endl;
            return true;
        }
        pii x = q1.front(), y = q2.front();
        //cerr << x.fi << ' ' << x.se << ' ' << y.fi << ' ' << y.se << endl;
        q1.pop();
        q2.pop();
        ae(x.fi)
            if(p->v != x.se && col[p->v] == col[x.fi])
                q1.push(pii(p->v, x.fi));
        ae(y.fi)
            if(p->v != y.se && col[p->v] == col[y.fi])
                q2.push(pii(p->v, y.fi));
    }
    //cerr << "geb" << endl;
    return false;
}
void dfs(int x, int fa)
{
    sum[tot] += a[x];
    ae(x)
        if(p->v != fa && col[p->v] == col[x])
            dfs(p->v, x);
    col[x] = tot;
}
int main()
{
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    __init();
    cin >> n >> m;
    enum(i, 1, n)
        cin >> a[i];
    open(i, 0, m)
        pool[i].input();
    sort(pool, pool + m);
    enum(i, 1, n)
        fa[i] = i;
    open(i, 0, m)
    {
        if(merge(pool[i].u, pool[i].v))
        {
            addrev(pool[i].u, pool[i].v);
            sta.push(pool[i]);
        }
    }
    enum(i, 1, n)
        sum[0] += a[i];
    //cerr << sta.size() << endl;
    // exit(0);
    while(!sta.empty())
    {
        //cerr << "Ha" << endl;
        ed p = sta.top();
        sta.pop();
        //cerr << "Ah" << endl;
        if(p.w > sum[col[p.u]])
        {
            tot ++;
            if(isbigger(pii(p.u, p.v), pii(p.v, p.u)))
            {
                dfs(p.v, p.u);
                sum[col[p.u]] -= sum[tot];
            }
            else
            {
                dfs(p.u, p.v);
                sum[col[p.v]] -= sum[tot];
            }
        }
    }
    int ans = 0;
    open(i, 0, m)
        if(col[pool[i].u] != col[pool[i].v] || sum[col[pool[i].u]] < pool[i].w)
            ans ++;
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 8384