#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long long ll;

ll price[100005];
pair <int, int> rebr[100005];
pair <ll, int> spis[100005];
int par[100005], sz[100005], remov[100005];
ll wei[100005];

int find_parent(int a)
{
    if (a == par[a]) return a;
    return par[a] = find_parent(par[a]);
}

void unions(int a, int b)
{
    a = find_parent(a), b = find_parent(b);
    if (a != b)
    {
        if (sz[a] < sz[b]) swap(a, b);
        sz[a] += sz[b], wei[a] += wei[b], remov[a] += remov[b];
        par[b] = a;
    }
    remov[a]++;
    return;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        cin >> price[i];
        par[i] = i, sz[i] = 1, wei[i] = price[i];
    }
    for (int i = 1; i <= m; i++)
    {
        int a, b;
        ll w;
        cin >> a >> b >> w;
        rebr[i] = mp(a, b);
        spis[i] = mp(w, i);
    }
    sort(spis + 1, spis + m + 1);

    for (int i = 1; i <= m; i++)
    {
        int a = rebr[spis[i].y].x, b = rebr[spis[i].y].y;
        unions(a, b);
        int v = find_parent(a);
        if (wei[v] >= spis[i].x) remov[v] = 0;
    }
    int v = find_parent(1);
    cout << remov[v];
    return 0;
}
