#include <bits/stdc++.h>
inline int getInt() {
  int s;
  scanf("%d", &s);
  return s;
}
using namespace std;
int main() {
  const int n = getInt();
  const int m = getInt();
  vector<long long> x(n);
  vector<set<pair<int, long long> > > e(n);
  vector<pair<long long, pair<int, int> > > v(m);
  for (int i = 0; i < (int)(n); i++) x[i] = getInt();
  vector<pair<int, int> > w(n);
  for (int i = 0; i < (int)(m); i++) {
    const int a = getInt() - 1;
    const int b = getInt() - 1;
    const int y = getInt();
    e[a].insert(make_pair(b, y));
    e[b].insert(make_pair(a, y));
    v[i] = make_pair(y, make_pair(a, b));
  }
  map<int, map<int, int> > done;
  sort(v.rbegin(), v.rend());
  vector<int> g(n);
  int gid = 1;
  int ans = 0;
  for (int i = 0; i < (int)(m); i++) {
    const int a = v[i].second.first;
    const int b = v[i].second.second;
    const long long y = v[i].first;
    if (done[a][b]) continue;
    long long cur = x[a] + x[b];
    {
      queue<int> q;
      q.push(a);
      q.push(b);
      g[a] = g[b] = gid;
      vector<int> p;
      p.push_back(a);
      p.push_back(b);
      while (q.size()) {
        const int pos = q.front();
        q.pop();
        for (auto ee : e[pos]) {
          const int next = ee.first;
          if (g[next] != gid) {
            g[next] = gid;
            cur += x[next];
            q.push(next);
          }
        }
      }
    }
    gid++;
    if (cur >= y) {
      queue<int> q;
      q.push(a);
      q.push(b);
      g[a] = g[b] = gid;
      vector<int> p;
      p.push_back(a);
      p.push_back(b);
      ans++;
      while (q.size()) {
        const int pos = q.front();
        q.pop();
        vector<pair<int, long long> > r;
        for (auto ee : e[pos]) {
          const int next = ee.first;
          if (g[next] != gid) {
            g[next] = gid;
            done[pos][next] = done[next][pos] = 1;
            r.push_back(ee);
            q.push(next);
            ans++;
          }
        }
        for (auto ee : r) {
          e[pos].erase(ee);
          e[ee.first].erase(make_pair(pos, ee.second));
        }
      }
    }
    e[a].erase(make_pair(b, y));
    e[b].erase(make_pair(a, y));
    gid++;
  }
  printf("%d\n", m - ans);
  return 0;
}
