#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int max(int a, int b) { return (a > b) ? a : b; }

const int MAXN = 100000;

int a[MAXN];
int b[MAXN];


const int INF = 1e9;

int w[MAXN];
int parent[MAXN];
int rankk[MAXN];
ll sum[MAXN];
int bad[MAXN];


int tim = 0;
vector<int> top;

vector<pair<int, pair<int, int>>> e;

void make_set (int v) {
    parent[v] = v;
    rankk[v] = 0;
    sum[v] = w[v];
    bad[v] = 0;
}

int find_set (int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set (parent[v]);
}

void union_sets (int a, int b) {
    a = find_set (a);
    b = find_set (b);
    if (a != b) {
        if (rankk[a] < rankk[b])
            swap (a, b);
        parent[b] = a;
        if (rankk[a] == rankk[b])
            ++rankk[a];
        sum[a] += sum[b];
        bad[a] += bad[b];
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> w[i];
    }
    e.resize(m);
    for (int i = 0; i < m; i++)
    {
        cin >> e[i].second.first >> e[i].second.second >> e[i].first;
        e[i].second.first--, e[i].second.second--;
    }
    sort(e.begin(), e.end());

    for (int i = 0; i < n; i++)
    {
        make_set(i);
    }

    for (auto& p : e)
    {
        int x = p.second.first;
        int y = p.second.second;
        int t = find_set(x);
        if (t != find_set(y))
        {
            union_sets(x, y);
            t = find_set(x);
        }
        if (sum[t] >= p.first)
        {
            bad[t] = 0;
        } else {
            bad[t]++;
        }
    }

    set<int> kek;
    for (int i = 0; i < n; i++)
    {
        kek.insert(find_set(i));
    }

    int ans = 0;
    for (int q : kek)
    {
        ans += bad[q];
    }
    cout << ans;
    return 0;
}