#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int N = (int)1e5 + 7;
int n, m;
int v[N];
vector<pair<int, int>> g[N];
vector<int> ids[N];
bool block[N];
long long s[N];
int where[N];
int y = 0;
bool viz[N];
int krr[N], lol;
inline void dfs(int nod) {
  krr[++lol] = nod;
  where[nod] = y;
  s[y] += v[nod];
  viz[nod] = 1;
  for (int i = 0; i < g[nod].size(); i++) {
    if (block[ids[nod][i]]) continue;
    auto it = g[nod][i];
    int nou = it.first;
    int co = it.second;
    if (viz[nou]) continue;
    dfs(nou);
  }
}
inline void clr() {
  for (int i = 1; i <= lol; i++) {
    viz[krr[i]] = 0;
  }
}
struct road {
  int a;
  int b;
  int x;
  int i;
};
bool cmp(road a, road b) { return a.x > b.x; }
inline void man(int a, int nod) {
  lol = 0;
  s[a] = 0LL;
  dfs(nod);
  clr();
}
bool del[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
  }
  vector<road> kek;
  for (int i = 1; i <= m; i++) {
    int a, b, x;
    cin >> a >> b >> x;
    g[a].push_back({b, x});
    ids[a].push_back(i);
    g[b].push_back({a, x});
    ids[b].push_back(i);
    kek.push_back({a, b, x, i});
  }
  sort(kek.begin(), kek.end(), cmp);
  for (int i = 1; i <= n; i++) {
    if (viz[i] == 0) {
      man(++y, i);
    }
  }
  int res = 0;
  for (auto &it : kek) {
    int a = it.a;
    int b = it.b;
    int x = it.x;
    if (s[where[a]] < x) {
      block[it.i] = 1;
      res++;
      del[where[a]] = 1;
      man(++y, a);
      if (where[a] != where[b]) {
        s[where[b]] -= s[where[a]];
      }
    }
  }
  cout << res << "\n";
  return 0;
}
