#include <bits/stdc++.h>
using namespace std;
int n, m, first[100010], nxt[100010 << 1], tot = 0;
int fa[100010], sum[100010], x, y, z, ans = 0;
long long w[100010];
long long Read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return f * x;
}
struct Edge {
  int u, v;
  long long w;
} edge[100010 << 1];
bool cmp(const Edge a, const Edge b) {
  if (a.w < b.w)
    return true;
  else
    return false;
}
void Add(int u, int v, int w) {
  tot++;
  nxt[tot] = first[u];
  first[u] = tot;
  edge[tot] = (Edge){u, v, w};
  return;
}
int Get(int x) {
  if (x == fa[x])
    return x;
  else
    return fa[x] = Get(fa[x]);
}
void Join(int x, int y) {
  fa[x] = y;
  w[y] += w[x];
  sum[y] += sum[x];
  return;
}
int main() {
  memset(first, -1, sizeof(first));
  n = Read(), m = Read();
  for (int i = 1; i <= n; i++) w[i] = Read();
  for (int i = 1; i <= m; i++) {
    x = Read(), y = Read(), z = Read();
    Add(x, y, z);
  }
  for (int i = 1; i <= n; i++) fa[i] = i;
  sort(edge + 1, edge + tot + 1, cmp);
  for (int i = 1; i <= tot; i++) {
    int u = edge[i].u, v = edge[i].v;
    int f1 = Get(u), f2 = Get(v);
    if (f1 != f2) Join(f1, f2);
    sum[f2]++;
    if (w[f2] >= edge[i].w) ans += sum[f2], sum[f2] = 0;
  }
  printf("%d\b", m - ans);
  return 0;
}
