//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include <ctime>
#include<list>
#include <numeric>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(int i = 0; i < n; i++)
#define FORAB(i, a, b) for(int i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))
#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int128 LL;
//typedef __int64 LL;

typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<long double, long double> PDD;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII > VP;
typedef vector<double> VD;
typedef vector<LL> VL;
typedef long double ld;

int par[100005];
struct Edge {
	int u, v, d;
} edge[100005];
bool operator<(Edge A, Edge B) {
	return A.d < B.d;
}
int n, m;
int w[100005];

int Par(int x) {
	if (x != par[x]) return par[x] = Par(par[x]);
	return x;
}
LL sum[100005];
int id[100005];
VI Z[100005];
LL sumZ[100005];

vector<Edge> E;
void Process(int at, int state) {
	if (at == -1) return;
	if (state == 0) {
		if (sumZ[at] >= edge[at].d) {
			E.push_back(edge[at]);
			for (int z : Z[at]) {
				Process(z, 1);
			}
		}
		else {
			for (int z : Z[at]) {
				Process(z, 0);
			}
		}
	}
	else {
		E.push_back(edge[at]);
		for (int z : Z[at]) {
			Process(z, 1);
		}
	}
}

void solve(int ks) {
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; i++) scanf("%d", &w[i]);
	for (int i = 0; i < m; i++) {
		scanf("%d %d %d", &edge[i].u, &edge[i].v, &edge[i].d);
	}
	sort(edge, edge + m);
	for (int i = 1; i <= n; i++) {
		par[i] = i;
		sum[i] = w[i];
		id[i] = -1;
	}
	int last = -1;
	for (int i = 0; i < m; i++) {
		int x = Par(edge[i].u);
		int y = Par(edge[i].v);
		if (x == y) {
			continue;
		}
		// x is child of y.
		Z[i] = { id[x], id[y] };
		par[x] = y;
		sum[y] += sum[x];
		sumZ[i] = sum[y];
		id[y] = i;
		last = i;
	}

	Process(last, 0);

	for (int i = 1; i <= n; i++) {
		par[i] = i;
		sum[i] = w[i];
	}
	for (Edge& e : E) {
		int x = Par(e.u);
		int y = Par(e.v);
		par[x] = y;
		sum[y] += sum[x];
	}

	int cnt = 0;
	for (int i = 0; i < m; i++) {
		int x = Par(edge[i].u);
		int y = Par(edge[i].v);
		if (x != y) {
			cnt++;
			continue;
		}
		if (sum[x] < edge[i].d) {
			cnt++;
		}
	}
	printf("%d\n", cnt);
}

int main()
{
#ifdef LOCAL
	double start_time = clock();
	freopen("C:\\Home\\ContestCodes\\sample.in", "r", stdin);
	//	freopen("out.out", "w", stdout);
#endif

	if (0) {
		int T;
		scanf("%d", &T);
		for (int ks = 1; ks <= T; ks++) solve(ks);
	}
	else {
		solve(0);
	}

#ifdef LOCAL
	double end_time = clock();
	fprintf(stderr, "Time = %lf\n", (end_time - start_time) / CLOCKS_PER_SEC);
#endif

	return 0;
}


Measured memory_bytes: 14068