#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long N, M;
long long X[100000], Y[1000000], A[1000000], B[1000000];
set<pair<long long, long long> > s[100000];
long long ans = 0;
long long used[100000];
long long sums[100000];
long long par[100000];
bool erased[100000];
set<pair<long long, long long> >::iterator ite[1000000];
long long nums[100000];
bool used2[100000];
bool qlog[100000];
long long find(long long x) {
  if (par[x] == x) return x;
  return par[x] = find(par[x]);
}
long long unite(long long x, long long y) {
  x = par[x];
  y = par[y];
  if (x == y) return 0;
  if (x > y) swap(x, y);
  return par[y] = x;
}
vector<int> er;
void solve(int V, long long S) {
  queue<long long> q;
  vector<long long> vs;
  int x, y;
  q.push(V);
  used[V]++;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    par[v] = v;
    qlog[v] = 0;
    sums[v] = X[v];
    nums[v] = 0;
    used2[v] = 0;
    for (ite[v] = s[v].begin(); ite[v] != s[v].end(); ++ite[v]) {
      pair<long long, long long> p = *(ite[v]);
      if (!erased[p.second] && Y[p.second] > S) {
        vs.push_back(v);
        vs.push_back(p.first);
        ans++;
        erased[p.second] = 1;
        er.push_back(p.second);
      }
      if (used[v] == used[p.first]) continue;
      used[p.first]++;
      q.push(p.first);
    }
    for (int(i) = 0; (i) < (er.size()); ++i) {
      s[A[er[i]]].erase(pair<long long, long long>(B[er[i]], er[i]));
      s[B[er[i]]].erase(pair<long long, long long>(A[er[i]], er[i]));
    }
  }
  long long cnt = 0;
  for (int(i) = 0; (i) < (vs.size()); ++i) {
    q.push(vs[i]);
    nums[vs[i]] = 1;
  }
  while (!q.empty() && cnt + 1 < vs.size()) {
    long long v = q.front();
    q.pop();
    qlog[v] = 1;
    nums[find(v)]--;
    for (ite[v] = s[v].begin(); ite[v] != s[v].end(); ++ite[v]) {
      x = find(v);
      y = find((*(ite[v])).first);
      if (x == y) continue;
      if (x > y) swap(x, y);
      par[y] = x;
      sums[x] += sums[y];
      nums[x] += nums[y];
      if (!qlog[(*(ite[v])).first]) {
        nums[x]++;
        q.push((*(ite[v])).first);
      }
    }
    if (nums[find(v)] == 0) cnt++;
  }
  long long s2 = S;
  for (int(i) = 0; (i) < (vs.size()); ++i) {
    if (vs[i] == find(vs[i]) && nums[find(vs[i])] == 0) s2 -= sums[find(vs[i])];
  }
  queue<pair<int, int> > q2;
  for (int(i) = 0; (i) < (vs.size()); ++i) {
    if (used2[find(vs[i])]) continue;
    int w = find(vs[i]);
    int h = nums[w] != 0 ? s2 : sums[w];
    q2.push(pair<long long, long long>(w, h));
    used2[find(vs[i])] = 1;
  }
  while (!q2.empty()) {
    pair<int, int> p = q2.front();
    q2.pop();
    solve(p.first, p.second);
  }
}
int main() {
  cin >> N >> M;
  long long SS = 0;
  for (int(i) = 0; (i) < (N); ++i) {
    cin >> X[i];
    SS += X[i];
  }
  for (int(i) = 0; (i) < (M); ++i) {
    cin >> A[i] >> B[i] >> Y[i];
    A[i]--;
    B[i]--;
    s[A[i]].insert(pair<long long, long long>(B[i], i));
    s[B[i]].insert(pair<long long, long long>(A[i], i));
  }
  solve(0, SS);
  cout << ans << endl;
}
