# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7; //924844033 1000000000 + 9;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum, ans, d[700000],a[200000], b[200000];
string str, ss;
bool f[200000];
char c[4000][4000];
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost; bool flag=0; };
struct edge { LL from, to, cost; };
vector<vector<Edge>>vec;
vector<edge>ed;
vector<LL>v;
map<string, LL>ma;
set<LL>st;

void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
int  par[200000];  // リーダーの値を格納 

int find(int x) { if (par[x] == x)return x; par[x] = find(par[x]); return par[x]; }
void unite(int x, int y) { x = find(x); y = find(y); if (x == y)return; par[x] = y; }
bool same(int x, int y) { return find(x) == find(y); }
void dfs(LL cur,LL par,LL cost) {
	if (f[cur])return;
	f[cur] = 1;
	rep(i, vec[cur].size()) {
		if (vec[cur][i].cost <= cost) {
			if (vec[cur][i].flag == 0) {
				vec[cur][i].flag = 1;
				ans++;
			}
			dfs(vec[cur][i].to, par,cost);
		}
	}
}
int main() {
	cin >> n >> m;
	rep(i, n) {
		cin >> a[i];
		d[i] = a[i];
	}
	vec.resize(n);
	for (int i = 0; i < n; i++)par[i] = i;  // このように初期化
	rep(i, m) {
		LL x, y, z;
		cin >> x >> y >> z;
		x--, y--;
		vec[x].push_back(Edge{ y,z });
		vec[y].push_back(Edge{ x,z });
		ed.push_back(edge{ x,y ,z });
	}
	sort(ed.begin(), ed.end(), [](edge x, edge y) {return x.cost < y.cost; });
	rep(i, ed.size()) {
		LL u = find(ed[i].from), t = find(ed[i].to), cost = ed[i].cost;
		if (u != t)
			cost -= d[u] + d[t];
		else
			cost -= d[u];
		if (cost <= 0) {
			v.push_back(i);
		}
		unite(u, t);
		if (u != t)
			d[t] += d[u];
	}
	for (int i = v.size() - 1; i >= 0; i--) {
		dfs(ed[v[i]].to, -1, ed[v[i]].cost);
	}
	cout << m-ans/2 << endl;
	return 0;
}


Measured memory_bytes: 24496