#include <bits/stdc++.h>
using namespace std;
const long long MAX_N = 100005;
set<long long> G[MAX_N];
long long x[MAX_N];
bool visit[MAX_N];
bool ed[MAX_N];
vector<pair<pair<long long, long long>, long long> > info;
void dfs(long long u, set<long long>& es, vector<long long>& ver,
         long long& sm) {
  visit[u] = true;
  sm += x[u];
  ver.push_back(u);
  for (auto&(p) : (G[u])) {
    es.insert(p);
    long long v = (info[p].first).second;
    if (!visit[v]) {
      dfs(v, es, ver, sm);
    }
  }
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < (long long)(n); ++i) {
    cin >> x[i];
  }
  info.resize(m);
  for (long long i = 0; i < (long long)(m); ++i) {
    long long a, b, y;
    cin >> a >> b >> y;
    info[i] = pair<pair<long long, long long>, long long>(
        pair<long long, long long>(a - 1, b - 1), y);
    G[a - 1].insert(i), G[b - 1].insert(i);
  }
  long long ans = 0;
  while (1) {
    for (long long i = 0; i < (long long)(n); ++i) {
      visit[i] = false;
    }
    for (long long i = 0; i < (long long)(n); ++i) {
      if (!visit[i] && !ed[i]) {
        set<long long> es;
        vector<long long> ver;
        long long val = 0;
        dfs(i, es, ver, val);
        long long res = 0;
        for (auto&(p) : (es)) {
          long long u = (info[p].first).first, v = (info[p].first).second;
          if (val < info[p].second) {
            G[u].erase(p), G[v].erase(p);
            res++;
          }
        }
        if (res == 0) {
          for (auto&(v) : (ver)) {
            ed[v] = true;
          }
        }
        ans += res;
      }
    }
    bool br = true;
    for (long long i = 0; i < (long long)(n); ++i) {
      if (!ed[i]) {
        br = false;
        break;
      }
    }
    if (br) break;
  }
  cout << ans << "\n";
  return 0;
}
