#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 * 1e9, SIZE = 1e5 + 10;
vector<long long> vec;
vector<tuple<long long, long long, long long>> edges, good;
vector<vector<pair<long long, long long>>> gr;
long long dsu[SIZE], siz[SIZE], sm[SIZE];
vector<pair<long long, long long>> upds;
map<tuple<long long, long long, long long>, long long> ind;
long long find(int v) {
  if (dsu[v] == v) return v;
  return dsu[v] = find(dsu[v]);
}
bool used[SIZE], usedE[SIZE];
void uni(int v, int u) {
  v = find(v);
  u = find(u);
  if (u == v) {
    return;
  }
  if (u != v) {
    sm[v] += sm[u];
    dsu[u] = v;
  }
}
long long cnt = 0;
void dfs(int v, int val, int vl) {
  used[v] = 1;
  for (auto to : gr[v]) {
    long long u1 = v, v1 = to.first;
    if (u1 > v1) swap(u1, v1);
    if (!usedE[ind[{u1, v1, to.second}]] && (to.second <= val) &&
        to.second <= vl) {
      usedE[ind[{u1, v1, to.second}]] = 1;
      cnt++;
    }
    if (!used[to.first]) {
      if (to.second <= vl && to.second <= val) dfs(to.first, val, vl);
    }
  }
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  ;
  long long n, m;
  cin >> n >> m;
  vec.resize(n);
  for (int i = 0; i < n; i++) cin >> vec[i];
  gr.resize(n);
  for (int i = 0; i < m; i++) {
    long long u, v, c;
    cin >> u >> v >> c;
    u--;
    v--;
    edges.push_back({c, u, v});
    gr[u].push_back({v, c});
    gr[v].push_back({u, c});
  }
  sort(edges.begin(), edges.end());
  gr.resize(n);
  for (int i = 0; i < n; i++) {
    dsu[i] = i;
    siz[i] = 1;
    sm[i] = vec[i];
  }
  vector<bool> good(m);
  vector<long long> vls(m);
  for (int i = 0; i < edges.size(); i++) {
    long long u = get<1>(edges[i]), v = get<2>(edges[i]);
    if (u > v) swap(u, v);
    ind[{u, v, get<0>(edges[i])}] = i;
    long long k = find(u), k2 = find(v);
    long long add = 0;
    if (k != k2) add = sm[k2];
    vls[i] = add + sm[k];
    if (sm[k] + add >= get<0>(edges[i])) good[i] = 1;
    if (find(u) != find(v)) {
      uni(u, v);
    }
  }
  queue<long long> q;
  for (int i = m - 1; i >= 0; i--) {
    if (good[i]) {
      dfs(get<1>(edges[i]), vls[i], get<0>(edges[i]));
    }
  }
  cout << m - cnt;
  return 0;
}
