#include <bits/stdc++.h>
using namespace std;
const int maxn = 112345;
int n, m, f[maxn], x[maxn];
long long sz[maxn];
bool vis[maxn];
struct edge {
  int u, v;
  long long w;
  inline bool operator<(const edge &rhs) const { return w < rhs.w; }
} e[maxn];
int F(int x) { return x == f[x] ? x : f[x] = F(f[x]); }
inline void U(int a, int b) {
  a = F(a);
  b = F(b);
  if (a == b) return;
  f[a] = b;
  sz[b] += sz[a];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &x[i]);
    sz[i] = x[i];
    f[i] = i;
  }
  for (int i = 0; i < m; ++i) {
    int tw;
    scanf("%d%d%d", &e[i].u, &e[i].v, &tw);
    e[i].w = tw;
  }
  sort(e, e + m);
  for (int o = 0; o < 1000; ++o) {
    for (int i = 1; i <= n; ++i) {
      f[i] = i;
      sz[i] = x[i];
    }
    for (int i = 0; i < m; ++i)
      if (!vis[i]) {
        int fu = F(e[i].u);
        int fv = F(e[i].v);
        if (fu != fv) U(fu, fv);
      }
    int cnt = 0;
    for (int i = 0; i < m; ++i)
      if (!vis[i]) {
        int fu = F(e[i].u);
        int fv = F(e[i].v);
        long long tmp = 0;
        if (fu != fv)
          tmp = sz[fu] + sz[fv];
        else
          tmp = sz[fu];
        if (tmp < e[i].w) {
          vis[i] = true;
          ++cnt;
        }
      }
    if (cnt == 0) break;
  }
  int res = 0;
  for (int i = 0; i < m; ++i) res += vis[i];
  printf("%d\n", res);
  return 0;
}
