#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
#define all(x) (x).begin(), (x).end()
int n, m;
struct Edge{
    int v, u, w;
};
bool comp(Edge A, Edge B)
{
    return A.w < B.w;
}
vector<Edge> edges;

int ans;
int root[500000];
int cnt[500000];
int sz[500000];
long long s[500000];

int Root(int x)
{
    if (x == root[x]) return x;
    return root[x] = Root(root[x]);
}

void Merge(Edge A)
{
    int u = A.u, v = A.v;
    u = Root(u);
    v = Root(v);
    if (u == v)
    {
        if (A.w <= s[v]) ans++;
        else cnt[v]++;
        return;
    }
    if (sz[u] > sz[v])
    {
        swap(v, u);
    }
    sz[v] += sz[u];
    s[v] += s[u];
    cnt[v] += cnt[u] + 1;
    root[u] = v;
    if (A.w <= s[v])
    {
        ans += cnt[v];
        cnt[v] = 0;
    }
    return;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> s[i], sz[i] = 1, root[i] = i;
    for (int i = 0; i < m; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        edges.push_back({a, b, c});
    }
    sort(all(edges), comp);
    for (int i = 0; i < m; i++)
    {
        Merge(edges[i]);
    }
    cout << m - ans;
}
