#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m, a[N], A, B, W, head[N], cnt, ans, store[N], tot, sum, b[N], maxn[N],
    now;
long long w[N];
bool check[N], pd[N], vis[N];
struct edge {
  int nxt, to, val, num;
} ed[N << 1];
struct edk {
  int a, b, c;
  edk(int aa = 0, int bb = 0, int cc = 0) {
    a = aa;
    b = bb;
    c = cc;
  }
} e[N], sk[N];
inline int f(int x) {
  if (x != b[x]) return b[x] = f(b[x]);
  return x;
}
inline bool cmp1(edk q, edk r) { return q.c < r.c; }
inline bool cmp2(edk q, edk r) {
  int f1 = f(q.a), f2 = f(q.b), f3 = f(r.a), f4 = f(r.b);
  return (f1 == f2 ? w[f1] : w[f1] + w[f2]) >
         (f3 == f4 ? w[f3] : w[f3] + w[f4]);
}
inline int addedge(int x, int y, int w, int num) {
  ed[++cnt].to = y;
  ed[cnt].nxt = head[x];
  ed[cnt].val = w;
  ed[cnt].num = num;
  head[x] = cnt;
  ed[++cnt].to = x;
  ed[cnt].nxt = head[y];
  ed[cnt].val = w;
  ed[cnt].num = num;
  head[y] = cnt;
}
inline void BFS(int u) {
  queue<int> q;
  q.push(u);
  vis[u] = true;
  store[++tot] = u;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (register int i = head[u]; i; i = ed[i].nxt) {
      int v = ed[i].to;
      if (!check[ed[i].num]) {
        check[ed[i].num] = true;
        e[++sum] = edk(u, v, ed[i].val);
      }
      if (!vis[v]) {
        vis[v] = true;
        store[++tot] = v;
        q.push(v);
      }
    }
  }
}
inline int Solve(int x) {
  tot = sum = 0;
  BFS(x);
  sort(e + 1, e + sum + 1, cmp1);
  int ss = tot, res = 0;
  now = 0;
  for (register int i = 1; i <= tot; i++) {
    b[store[i]] = store[i];
    w[store[i]] = a[store[i]];
    pd[store[i]] = true;
  }
  for (register int i = 1; i <= sum; i = now + 1) {
    sk[now = i] = e[i];
    while (e[now + 1].c == e[i].c) now++, sk[now] = e[now];
    sort(sk + i, sk + now + 1, cmp2);
    for (register int j = i; j <= now; j++) {
      int x = sk[j].a, y = sk[j].b, v = sk[j].c;
      int f1 = f(x), f2 = f(y);
      if (f1 != f2) {
        w[f1] += w[f2];
        maxn[f1] = max(maxn[f1], max(maxn[f2], v));
        if (!pd[f2]) pd[f2] = true, ss++;
        if (w[f1] < maxn[f1] && pd[f1]) pd[f1] = false, ss--;
        if (w[f1] >= maxn[f1] && !pd[f1]) pd[f1] = true, ss++;
        b[f2] = f1;
      } else {
        maxn[f1] = max(maxn[f1], v);
        if (w[f1] < maxn[f1] && pd[f1]) pd[f1] = false, ss--;
        if (w[f1] >= maxn[f1] && !pd[f1]) pd[f1] = true, ss++;
      }
      if (ss == tot) res = max(res, j);
    }
  }
  return res;
}
int main() {
  scanf("%d%d", &n, &m);
  for (register int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (register int i = 1; i <= m; i++)
    scanf("%d%d%d", &A, &B, &W), addedge(A, B, W, i);
  for (register int i = 1; i <= n; i++)
    if (!vis[i]) ans += Solve(i);
  printf("%d\n", m - ans);
  return 0;
}
