#include <bits/stdc++.h>
using namespace std;
struct edge {
  long long u, v;
  edge *next;
} egp[200005 << 1], *h[200005];
long long egcnt = 0;
void addedge(long long u, long long v) {
  edge *n1 = &egp[egcnt++];
  n1->u = u, n1->v = v, n1->next = h[u], h[u] = n1;
}
long long dfn[200005], pre[200005], dep[200005], size[200005], son[200005],
    top[200005];
long long tr[200005];
long long num[200005];
long long sum[200005];
long long dfcnt = 0;
void dfs1(long long a) {
  size[a] = 1;
  sum[a] = num[a];
  for (edge *p = h[a]; p; p = p->next) {
    if (p->v == pre[a]) continue;
    dep[p->v] = dep[a] + 1, pre[p->v] = a;
    dfs1(p->v);
    sum[a] += sum[p->v];
    size[a] += size[p->v];
    if (size[p->v] > size[son[a]]) son[a] = p->v;
  }
}
void dfs2(long long a) {
  dfn[a] = ++dfcnt;
  if (son[a]) top[son[a]] = top[a], dfs2(son[a]);
  for (edge *p = h[a]; p; p = p->next) {
    if (p->v == pre[a] || p->v == son[a]) continue;
    top[p->v] = p->v, dfs2(p->v);
  }
}
struct ST {
  ST *ch[2];
  long long lz;
  long long l, r, mxs;
} stp[200005 << 2], *root;
long long stcnt = 0;
void bdtree(ST *a, long long l, long long r) {
  a->l = l, a->r = r, a->mxs = -1, a->lz = 0;
  if (l == r) return;
  long long mid = (l + r) >> 1;
  a->ch[0] = &stp[stcnt++], a->ch[1] = &stp[stcnt++];
  bdtree(a->ch[0], l, mid), bdtree(a->ch[1], mid + 1, r);
}
void ins(ST *a, long long pl) {
  a->mxs = max(a->mxs, pl);
  if (a->l == a->r) return;
  long long mid = (a->l + a->r) >> 1;
  if (pl <= mid)
    ins(a->ch[0], pl);
  else
    ins(a->ch[1], pl);
}
void push(ST *a, long long l, long long r, long long s) {
  if (a->l == l && a->r == r) {
    a->lz += s;
    return;
  }
  long long mid = (a->l + a->r) >> 1;
  if (r <= mid)
    push(a->ch[0], l, r, s);
  else if (l > mid)
    push(a->ch[1], l, r, s);
  else
    push(a->ch[0], l, mid, s), push(a->ch[1], mid + 1, r, s);
}
long long qmx(ST *a, long long l, long long r) {
  if (a->l == l && a->r == r) return a->mxs;
  long long mid = (a->l + a->r) >> 1;
  if (r <= mid)
    return qmx(a->ch[0], l, r);
  else if (l > mid)
    return qmx(a->ch[1], l, r);
  else
    return max(qmx(a->ch[0], l, mid), qmx(a->ch[1], mid + 1, r));
}
long long qsum(ST *a, long long pl) {
  if (a->l == a->r) return a->lz;
  long long mid = (a->l + a->r) >> 1;
  if (pl <= mid)
    return a->lz + qsum(a->ch[0], pl);
  else
    return a->lz + qsum(a->ch[1], pl);
}
long long gf(long long x) {
  while (x) {
    long long ns = qmx(root, dfn[top[x]], dfn[x]);
    if (ns != -1) return tr[ns];
    x = pre[top[x]];
  }
  while (1)
    ;
}
long long q(long long pl) {
  long long rf = gf(pl);
  return sum[rf] - qsum(root, dfn[rf]);
}
void cut(long long u, long long v) {
  if (pre[v] == u) swap(u, v);
  if (pre[u] != v)
    while (1)
      ;
  long long n1 = q(u);
  long long rf = gf(u);
  ins(root, u);
  u = pre[u];
  while (dep[u] >= dep[rf]) {
    if (dep[top[u]] >= dep[rf])
      push(root, dfn[top[u]], dfn[u], n1), u = pre[top[u]];
    else {
      if (top[rf] != top[u])
        while (1)
          ;
      push(root, dfn[rf], dfn[u], n1), u = pre[rf];
    }
  }
}
long long fa[200005];
long long gfa(long long a) {
  if (fa[a] == a) return a;
  return fa[a] = gfa(fa[a]);
}
struct eg {
  long long u, v, w, fl;
  bool operator<(const eg &x) const { return w < x.w; }
} p[200005];
int main() {
  long long n, m;
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= n; i++) scanf("%lld", &num[i]), fa[i] = i;
  for (long long i = 1; i <= m; i++)
    scanf("%lld%lld%lld", &p[i].u, &p[i].v, &p[i].w);
  sort(p + 1, p + m + 1);
  for (long long i = 1; i <= m; i++) {
    long long ufa = gfa(p[i].u), vfa = gfa(p[i].v);
    if (ufa == vfa)
      p[i].fl = 0;
    else
      p[i].fl = 1, fa[ufa] = vfa, addedge(p[i].u, p[i].v),
      addedge(p[i].v, p[i].u);
  }
  dep[1] = 1, top[1] = 1;
  dfs1(1), dfs2(1);
  for (long long i = 1; i <= n; i++) tr[dfn[i]] = i;
  root = &stp[stcnt++];
  bdtree(root, 1, n);
  ins(root, 1);
  long long cnt = 0;
  for (long long i = m; i >= 1; i--) {
    long long ns = q(p[i].u);
    long long n2 = q(p[i].v);
    if (ns != n2)
      while (1)
        ;
    if (ns >= p[i].w)
      continue;
    else {
      cnt++;
      if (p[i].fl) {
        cut(p[i].u, p[i].v);
      }
    }
  }
  printf("%d\n", cnt);
  return 0;
}
