#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, sz[100005], f[100005], sum[100005], fa[100005], px[100005],
    py[100005], pz[100005], vis[100005], tag[100005];
struct ed {
  int id, z;
} a[100005];
bool cmp(ed x, ed y) { return x.z < y.z; }
int fnd(int x) {
  if (fa[x] == x) return x;
  return fnd(fa[x]);
}
stack<int> sx, sy;
void merge(int x, int y) {
  x = fnd(x);
  y = fnd(y);
  if (sz[x] > sz[y]) swap(x, y);
  sum[y] += sum[x];
  fa[x] = y;
  if (sz[x] == sz[y]) sz[y]++;
  sx.push(x);
  sy.push(y);
}
void chexiao() {
  int x = sx.top(), y = sy.top();
  sx.pop();
  sy.pop();
  fa[x] = x;
  sum[y] -= sum[x];
  if (tag[y]) tag[x] = 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%d", &sum[i]);
  }
  for (i = 1; i <= m; i++) {
    scanf("%d%d%d", &px[i], &py[i], &pz[i]);
    a[i] = (ed){i, pz[i]};
  }
  for (i = 1; i <= n; i++) {
    sz[i] = 1;
    fa[i] = i;
  }
  sort(a + 1, a + m + 1, cmp);
  for (i = 1; i <= m; i++) {
    int t = a[i].id;
    if (fnd(px[t]) != fnd(py[t])) {
      merge(px[t], py[t]);
      vis[t] = 1;
    }
  }
  int ans = 0;
  for (i = m; i; i--) {
    int t = a[i].id;
    if (tag[fnd(px[t])] || sum[fnd(px[t])] >= pz[t])
      tag[fnd(px[t])] = 1;
    else
      ans++;
    if (vis[t]) chexiao();
  }
  cout << ans << endl;
  return 0;
}
