#include <bits/stdc++.h>
using namespace std;
long long vw[114514];
long long par[114514];
long long rankk[114514];
long long siz[114514];
long long cand[114514];
long long used[114514];
vector<pair<long long, long long> > nex[114514];
void init(long long n) {
  for (long long i = 1; i <= n; i++) {
    par[i] = i;
    rankk[i] = 0;
    siz[i] = vw[i];
  }
}
long long find(long long x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}
void unite(long long x, long long y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  if (rankk[x] < rankk[y]) {
    par[x] = y;
    siz[y] = siz[x] + siz[y];
  } else {
    par[y] = x;
    siz[x] = siz[x] + siz[y];
    if (rankk[x] == rankk[y]) rankk[x]++;
  }
}
signed main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    cin >> vw[i];
  }
  vector<pair<long long, pair<long long, long long> > > ed;
  for (long long i = 0; i < m; i++) {
    long long ta, tb, ty;
    cin >> ta >> tb >> ty;
    ed.push_back(make_pair(ty, make_pair(ta, tb)));
    nex[ta].push_back(make_pair(tb, i));
    nex[tb].push_back(make_pair(ta, i));
  }
  sort(ed.begin(), ed.end());
  init(110000);
  for (long long i = 0; i < m; i++) {
    long long lef = ed[i].second.first;
    long long rig = ed[i].second.second;
    unite(lef, rig);
    if (siz[find(lef)] >= ed[i].first) {
      cand[i] = 1;
    }
  }
  reverse(ed.begin(), ed.end());
  long long ans = 0;
  for (long long i = 0; i < m; i++) {
    if (used[i] == 0) {
      if (cand[m - 1 - i] == 0)
        ans++;
      else {
        queue<long long> que;
        long long cw = ed[i].first;
        long long lef = ed[i].second.first;
        long long rig = ed[i].second.second;
        que.push(lef);
        que.push(rig);
        used[i] = 1;
        while (!que.empty()) {
          long long cur = que.front();
          que.pop();
          for (long long i = 0; i < nex[cur].size(); i++) {
            pair<long long, long long> nx = nex[cur][i];
            long long ew = ed[nx.second].first;
            if (used[nx.second] == 0 && ew <= cw) {
              used[nx.second] = 1;
              que.push(nx.first);
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
