#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
long long dat[100005 << 2], x[100005], y[100005];
int n, m, par[100005], hei[100005];
struct edge {
  int u, v, w;
  bool operator<(const edge &e) const { return w < e.w; }
} el[100005];
void build(int id, int l, int r) {
  if (l == r)
    dat[id] = x[l];
  else {
    int mid = (l + r) >> 1;
    build(id << 1, l, mid);
    build(id << 1 | 1, mid + 1, r);
    dat[id] = min(dat[id << 1], dat[id << 1 | 1]);
  }
}
void update(int id, int l, int r, int pos, long long val) {
  if (l == r)
    dat[id] = val;
  else {
    int mid = (l + r) >> 1;
    if (pos <= mid)
      update(id << 1, l, mid, pos, val);
    else
      update(id << 1 | 1, mid + 1, r, pos, val);
    dat[id] = min(dat[id << 1], dat[id << 1 | 1]);
  }
}
void ini() {
  for (int i = 1; i <= n; i++) {
    par[i] = i;
    hei[i] = 1;
  }
}
int fin(int u) {
  if (par[u] == u) return u;
  return par[u] = fin(par[u]);
}
void uni(int u, int v, int w) {
  u = fin(u), v = fin(v);
  if (u == v) {
    y[u] = w;
    update(1, 1, n, u, x[u] - y[u]);
  } else {
    if (hei[u] < hei[v]) {
      par[u] = v;
      update(1, 1, n, u, 0);
      x[v] += x[u];
      y[v] = w;
      update(1, 1, n, v, x[v] - y[v]);
    } else {
      par[v] = u;
      update(1, 1, n, v, 0);
      x[u] += x[v];
      y[u] = w;
      update(1, 1, n, u, x[u] - y[u]);
      if (hei[u] == hei[v]) hei[u]++;
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%lld", &x[i]);
  ini();
  for (int i = 1; i <= m; i++) scanf("%d%d%d", &el[i].u, &el[i].v, &el[i].w);
  sort(el + 1, el + m + 1);
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    uni(el[i].u, el[i].v, el[i].w);
    if (dat[1] >= 0) ans = i;
  }
  printf("%d\n", m - ans);
  return 0;
}
