#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i,a,b) for(int i=(a);i<=(b);++i)
#define FD(i,b,a) for(int i=(b);i>=(a);--i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;
int inv(LL x, int m) { return x > m ? inv(x % m, m) : x > 1 ? inv(m % x, m) * (m - m / x) % m : x; }
int mpow(LL a, LL k, int m) { int r(1); for (a %= m; k; k >>= 1, a = a * a % m) if (k & 1)r = r * a % m; return r; }


const int N = 1e5 + 5;
int n, m, F[N], C[N];
LL X[N];
struct Edge { int u, v, w; } E[N];
int root(int x) { return F[x] < 0 ? x : F[x] = root(F[x]); }
int size(int x) { return -F[root(x)]; }
bool same(int x, int y) { return root(x) == root(y); }
bool unite(int x, int y) {
    x = root(x), y = root(y);
    if (x != y) {
        if (F[y] < F[x]) swap(x, y);
        F[x] += F[y], F[y] = x, X[x] += X[y], C[x] += C[y];
    }
    return x != y;
}

int main() {
    memset(F, -1, sizeof F);
    cin >> n >> m;
    FI(i, 1, n) scanf("%lld", &X[i]);
    FI(i, 1, m) scanf("%d%d%d", &E[i].u, &E[i].v, &E[i].w);
    sort(E + 1, E + 1 + m, [](Edge a, Edge b) { return a.w < b.w; });
    FI(i, 1, m) {
        int u = E[i].u, v = E[i].v, w = E[i].w;
        u = root(u), v = root(v);
        if (u == v) {
            if (X[u] < w) C[u]++;
            continue;
        }
        if (X[u] + X[v] >= w) C[u] = C[v] = 0;
        else C[u]++;
        unite(u, v);
    }
    int r = root(1);
    cout << C[r] << endl;
}
