#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
struct UnionFind {
	vector<int> data;
	vector<int> horyu;
	vector<int> sum;
	int all = 0;
	UnionFind(vector<int> &X) {
		int size = X.size();
		sum = X;
		data.resize(size, -1);
		horyu.resize(size, 0);

	}

	bool unionSet(int x, int y, int w) {

		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
			sum[x] += sum[y];
			horyu[x] += horyu[y];

		}
		horyu[x]++;
		//cerr << x <<" " << y << " " << w << " " << sum[x] << endl;
		if (w <= sum[x]) {
			all += horyu[x];
			horyu[x] = 0;
		}

		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};
struct E {
	int w;
	int a;
	int b;
	bool operator<(const E &right) const {
		return w < right.w;
	}
};
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<int> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	UnionFind uf(A);
	vector<E> es;
	int a, b, w;
	for (int i = 0; i < M; i++) {
		cin >> a >> b >> w; a--; b--;
		es.push_back(E{ w,a,b });
	}
	sort(es.begin(), es.end());

	for (int i = 0; i < M; i++) {
		uf.unionSet(es[i].a, es[i].b, es[i].w);
	}
	cout << M - uf.all << endl;
}