#include <bits/stdc++.h>
using namespace std;
const int mod = 1000 * 1000 * 1000 + 7;
const long long LINF = 1000 * 1000 * 1000 * (long long)1000 * 1000 * 1000;
const int MAX = 1 << 17;
int comp[MAX];
int sub[MAX];
int p[MAX];
int p2[MAX];
int first[MAX];
int used[MAX];
long long waga[MAX];
long long waga2[MAX];
int depth[MAX];
int Comp = 4;
int N, M;
vector<pair<int, int> > ob[MAX];
vector<vector<pair<int, int> > > g(MAX);
void init() {
  for (int i = 0; i < N; i++) {
    p[i] = i;
  }
}
int find2(int u) {
  if (u == p2[u]) return u;
  return p2[u] = find2(p2[u]);
}
void unite2(int u, int v) {
  u = find2(u), v = find2(v);
  p2[v] = u;
  if (u != v) waga2[u] += waga2[v];
}
int find(int u) {
  if (u == p[u]) return u;
  return p[u] = find(p[u]);
}
void unite(int u, int v) {
  u = find(u), v = find(v);
  if (ob[v].size() > ob[u].size()) swap(u, v);
  for (auto zalupa : ob[v]) {
    ob[u].push_back(zalupa);
  }
  p[v] = u;
  waga[u] += waga[v];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> N >> M;
  init();
  for (int i = 0; i < N; i++) {
    cin >> first[i];
    waga2[i] = waga[i] = first[i];
  }
  vector<pair<int, pair<int, int> > > edges;
  for (int i = 0; i < M; i++) {
    int u, v, y;
    cin >> u >> v >> y;
    u--;
    v--;
    edges.push_back({y, {u, v}});
  }
  sort(edges.begin(), edges.end());
  vector<pair<int, pair<int, int> > > rebra, rebra2;
  for (int i = 0; i < edges.size(); i++) {
    int u = edges[i].second.first, v = edges[i].second.second;
    if (find(u) != find(v)) {
      unite(u, v);
      rebra.push_back(edges[i]);
    } else
      rebra2.push_back(edges[i]);
  }
  for (int i = 0; i < N; i++) {
    p[i] = p2[i] = i;
    waga2[i] = waga[i] = first[i];
  }
  int ans = 0;
  cout << endl;
  for (int i = 0; i < N - 1; i++) {
    int u = rebra[i].second.first, v = rebra[i].second.second;
    int pU = find(u), pV = find(v);
    if (waga[pU] + waga[pV] >= rebra[i].first) {
      ans++;
      unite(u, v);
      unite2(u, v);
      for (auto u : ob[pU]) {
        unite2(u.first, u.second);
        ans++;
      }
      for (auto u : ob[pV]) {
        unite2(u.first, u.second);
        ans++;
      }
      ob[pU].clear();
      ob[pV].clear();
    } else {
      unite(u, v);
      ob[find(u)].push_back({u, v});
    }
  }
  for (auto rebro : rebra2) {
    ans += find2(rebro.second.first) == find2(rebro.second.second) &&
           waga2[find2(rebro.second.first)] >= rebro.first;
  }
  cout << M - ans;
}
