#include <bits/stdc++.h>
using namespace std;
long long M = 1000000007;
int n, m;
vector<vector<int>> G;
vector<long long> y;
vector<long long> x;
vector<pair<int, int>> edges;
vector<bool> live, seen;
vector<int> ve;
long long w;
long long tmp;
void dfs(int u) {
  if (seen[u]) return;
  seen[u] = true;
  ve.push_back(u);
  for (int k : G[u]) {
    if (live[k]) dfs(edges[k].second);
  }
  return;
}
int main(int argc, char const *argv[]) {
  cin >> n >> m;
  y = vector<long long>(n);
  x = vector<long long>(m);
  G = vector<vector<int>>(n);
  edges = vector<pair<int, int>>(0);
  for (int i = 0; i < n; ++i) cin >> y[i];
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v >> x[i];
    u--;
    v--;
    edges.push_back(pair<int, int>(u, v));
    edges.push_back(pair<int, int>(v, u));
    G[u].push_back(2 * i);
    G[v].push_back(2 * i + 1);
  }
  long long res = 0;
  live = vector<bool>(2 * m, true);
  while (true) {
    bool b = false;
    seen = vector<bool>(n, false);
    for (int u = 0; u < n; ++u) {
      if (!seen[u]) {
        ve = vector<int>(0);
        dfs(u);
        long long tmp = 0;
        for (int v : ve) tmp += y[v];
        for (int v : ve) {
          for (int k : G[v]) {
            if (live[k] && x[k / 2] > tmp) {
              res++;
              live[2 * (k / 2)] = false;
              live[2 * (k / 2) + 1] = false;
              b = true;
            }
          }
        }
      }
    }
    if (!b) break;
  }
  cout << res << endl;
  return 0;
}
