#include <bits/stdc++.h>
int unicnt[(1 << 17) + 10];
int cnt[100010];
void ufinit(int n) {
  for (long long i = (0); i < (n); i++) unicnt[i] = 1;
}
int root(int x) {
  return unicnt[x] <= 0 ? -(unicnt[x] = -root(-unicnt[x])) : x;
}
int same(int x, int y) { return root(x) == root(y); }
void uni(int x, int y) {
  if ((x = root(x)) == (y = root(y))) return;
  if (rand() % 2) {
    int t = x;
    x = y;
    y = t;
  }
  unicnt[x] += unicnt[y];
  unicnt[y] = -x;
  cnt[x] += cnt[y];
}
typedef struct edge {
  long long s, g, c;
} E;
typedef struct graph {
  long long vcnt, ecnt;
  E e[100010];
} G;
int csort(const void* a, const void* b) {
  long long p = (*(E*)a).c, q = (*(E*)b).c;
  return p < q ? -1 : p > q ? 1 : 0;
}
G g;
long long x[100010];
void readgraph() {
  long long n, m;
  scanf("%lld%lld", &n, &m);
  for (long long i = (0); i < (n); i++) scanf("%lld", x + i);
  for (long long i = (0); i < (m); i++) {
    long long x, y, c;
    scanf("%lld%lld%lld", &x, &y, &c);
    x--, y--;
    g.e[i].s = x;
    g.e[i].g = y;
    g.e[i].c = c;
  }
  g.vcnt = n;
  g.ecnt = m;
  qsort(g.e, g.ecnt, sizeof(E), csort);
}
long long ans;
int main() {
  readgraph();
  for (long long i = (0); i < (g.vcnt); i++) unicnt[i] = x[i];
  for (long long i = (0); i < (g.ecnt); i++) {
    uni(g.e[i].s, g.e[i].g);
    cnt[root(g.e[i].s)]++;
    if (unicnt[root(g.e[i].s)] >= g.e[i].c) {
      ans += cnt[root(g.e[i].s)];
      cnt[root(g.e[i].s)] = 0;
    }
  }
  printf("%lld\n", g.ecnt - ans);
}
