/*
    Take me to church
    I'll worship like a dog at the shrine of your lies
    I'll tell you my sins and you can sharpen your knife
    Offer me that deathless death
    Good God, let me give you my life
*/
#include<bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m, cnt, A[N], V[N], U[N], W[N], S[N], M[N], MR[N];
long long P[N];
vector < pair < int , int > > Adj[N];
inline bool CMP(int i, int j)
{
    return (W[i] < W[j]);
}
long long Find(int v)
{
    return ((P[v] < 0) ? v : (P[v] = Find(P[v])));
}
void DFS(int v, int w)
{
    M[v] = 1;
    for (auto u : Adj[v])
    {
        if (u.second <= w)
            cnt ++;
        if (!M[u.first] && u.second <= w)
            DFS(u.first, w);
    }
}
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i ++)
        scanf("%d", &A[i]), P[i] = - A[i];
    for (int i = 1; i <= m; i ++)
    {
        scanf("%d%d%d", &V[i], &U[i], &W[i]), S[i] = i;
        Adj[V[i]].push_back({U[i], W[i]});
        Adj[U[i]].push_back({V[i], W[i]});
    }
    sort(S + 1, S + m + 1, CMP);
    for (int j = 1; j <= m; j ++)
    {
        int i = S[j];
        if (Find(V[i]) != Find(U[i]))
            P[Find(V[i])] += P[Find(U[i])], P[Find(U[i])] = Find(V[i]);
        if (- P[Find(V[i])] >= W[i])
            MR[i] = 1;
    }
    for (int j = m; j; j --)
    {
        int i = S[j];
        if (MR[i] && !M[V[i]])
            DFS(V[i], W[i]);
    }
    return !printf("%d\n", m - cnt / 2);
}