#include <stdio.h>
#include <stdlib.h>
#define int long long

typedef struct {
	int N;
	int *u;
	int *u_rank;
}union_find;

union_find *make_union_find(int N){
	int i;
	union_find *uf = (union_find *)malloc(sizeof(union_find));
	uf->N = N;
	uf->u = (int *)malloc(sizeof(int) * N);
	uf->u_rank = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		uf->u[i] = i;
		uf->u_rank[i] = 1;
	}
	return uf;
}

int root_uf(int x, union_find *uf){
	int *u = uf->u;
	if(u[x] == x){
		return x;
	}
	else{
		u[x] = root_uf(u[x], uf);
		return u[x];
	}
}

void combine_uf(int x, int y, union_find *uf){
	int x_root = root_uf(x, uf);
	int y_root = root_uf(y, uf);
	int *u = uf->u;
	int *u_rank = uf->u_rank;
	if(x_root == y_root){
		return;
	}
	else if(u_rank[x_root] < u_rank[y_root]){
		u[x_root] = y_root;
		u_rank[y_root] += u_rank[x_root];
		u_rank[x_root] = 0;
	}
	else{
		u[y_root] = x_root;
		u_rank[x_root] += u_rank[y_root];
		u_rank[y_root] = 0;
	}
}

//xとyが同じ集合に属していれば1を,そうでなければ0を返す
int is_same_union_uf(int x, int y, union_find *uf){
	if(root_uf(x, uf) == root_uf(y, uf)){
		return 1;
	}
	else{
		return 0;
	}
}

//xが属する集合の要素数を返す
int rank_uf(int x, union_find *uf){
	return uf->u_rank[root_uf(x, uf)];
}

typedef struct {
	int A;
	int B;
	int Y;
}tuple;

signed compare_tuple(const void *a, const void *b){
	int sub = ((tuple *)a)->Y - ((tuple *)b)->Y;
	if(sub < 0){
		return -1;
	}
	else if(sub == 0){
		return 0;
	}
	else{
		return 1;
	}
}

signed main(){
	int N, M, A, B, Y, i;
	scanf("%lld%lld", &N, &M);
	int *X = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%lld", &X[i]);
	}
	tuple *tps = (tuple *)malloc(sizeof(tuple) * M);
	for(i = 0; i < M; i++){
		scanf("%lld%lld%lld", &tps[i].A, &tps[i].B, &tps[i].Y);
		tps[i].A--;
		tps[i].B--;
	}
	qsort(tps, M, sizeof(tuple), compare_tuple);
	union_find *uf = make_union_find(N);
	int *edge_num = (int *)malloc(sizeof(int) * N);
	int *good_edge_num = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		edge_num[i] = 0;
		good_edge_num[i] = 0;
	}
	int ans = 0;
	int r, rA, rB;
	for(i = 0; i < M; i++){
		A = tps[i].A;
		B = tps[i].B;
		Y = tps[i].Y;
//		printf("(A, B, Y)[%lld] = (%lld, %lld, %lld)\n", i, A, B, Y);
		if(is_same_union_uf(A, B, uf) == 1){
//			printf("test3\n");
			r = root_uf(A, uf);
			edge_num[r]++;
			if(X[r] >= Y){
//				printf("test4\n");
				good_edge_num[r]++;
				ans++;
			}
//			printf("(edge_num, good_edge_num)[%lld] = (%lld, %lld)\n", r, edge_num[r], good_edge_num[r]);
		}
		else{
//			printf("test5\n");
			rA = root_uf(A, uf);
			rB = root_uf(B, uf);
//			printf("(rA, rB) = (%lld, %lld)\n", rA, rB);
			combine_uf(A, B, uf);
			r = root_uf(A, uf);
			X[r] = X[rA] + X[rB];
//			printf("X[%lld] = %lld\n", r, X[r]);
			if(X[r] >= Y){
//				printf("test6\n");
				ans += (edge_num[rA] - good_edge_num[rA]) + (edge_num[rB] - good_edge_num[rB]) + 1;
				good_edge_num[r] = edge_num[rA] + edge_num[rB] + 1;
				edge_num[r] = edge_num[rA] + edge_num[rB] + 1;
			}
			else{
//				printf("test7\n");
				good_edge_num[r] = good_edge_num[rA] + good_edge_num[rB];
				edge_num[r] = edge_num[rA] + edge_num[rB] + 1;
			}
//			printf("(edge_num, good_edge_num)[%lld] = (%lld, %lld)\n", r, edge_num[r], good_edge_num[r]);
		}
//		printf("ans = %lld\n", ans);
	}
	printf("%lld\n", M - ans);
	return 0;
}

Measured memory_bytes: 6484