#include <bits/stdc++.h>
using namespace std;
class unionfind {
 public:
  int par[200000];
  int ran[200000];
  long long ren[200000];
  vector<int> ko[200000];
  bool isact[200000];
  void init() {
    for (int i = 0; i < 200000; i++) {
      par[i] = i;
    }
  }
  int find(int a) {
    if (a == par[a])
      return a;
    else
      return find(par[a]);
  }
  int actfind(int a) {
    if (a == par[a] || !isact[a])
      return a;
    else
      return actfind(par[a]);
  }
  void unite(int a, int b) {
    a = find(a);
    b = find(b);
    if (a == b) return;
    if (ran[a] > ran[b]) {
      par[b] = a;
      ren[a] += ren[b];
      ko[a].push_back(b);
    } else {
      par[a] = b;
      ren[b] += ren[a];
      ko[b].push_back(a);
    }
    if (ran[a] == ran[b]) ran[b]++;
  }
  void activate(int a) {
    for (int i = 0; i < ko[a].size(); i++) {
      if (isact[ko[a][i]]) continue;
      activate(ko[a][i]);
      isact[ko[a][i]] = true;
    }
  }
};
unionfind uf;
long long wei[202020];
int dat[202020];
long long sum[202020];
int main() {
  int num, way;
  scanf("%d%d", &num, &way);
  uf.init();
  for (int i = 0; i < num; i++) scanf("%lld", &uf.ren[i]), wei[i] = uf.ren[i];
  vector<pair<long long, pair<long long, long long> > > v;
  for (int i = 0; i < way; i++) {
    int za, zb, zc;
    scanf("%d%d%d", &za, &zb, &zc);
    za--, zb--;
    v.push_back(make_pair(zc, make_pair(za, zb)));
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) {
    int s = v[i].second.first, t = v[i].second.second;
    long long d = v[i].first;
    if (uf.find(s) == uf.find(t)) continue;
    uf.unite(s, t);
    if (uf.ren[uf.find(s)] >= d) uf.activate(uf.find(s));
  }
  for (int i = 0; i < num; i++)
    dat[i] = uf.actfind(i), sum[uf.actfind(i)] += wei[i];
  int r = 0;
  for (int i = 0; i < v.size(); i++) {
    int s = v[i].second.first, t = v[i].second.second;
    long long d = v[i].first;
    if (dat[s] != dat[t] || sum[dat[s]] < d) r++;
  }
  printf("%d\n", r);
}
