#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &n) {
  n = 0;
  register int ch;
  while (!isdigit(ch = getchar()))
    ;
  for (n = ch ^ 48; isdigit(ch = getchar()); n = n * 10 + (ch ^ 48))
    ;
}
int const MAXN = 2e5 + 5;
struct Edges {
  int x, y;
  long long val;
} e[MAXN];
long long a[MAXN], Rsize[MAXN], Esize[MAXN];
int vis[MAXN], fa[MAXN], child[MAXN][2], r[MAXN], stk[MAXN], top;
inline bool cmp(Edges x, Edges y) { return x.val < y.val; }
inline void Update(int x) {
  Rsize[x] = Rsize[child[x][0]] + Rsize[child[x][1]] + Esize[x] + a[x];
}
inline bool Isroot(int x) {
  return child[fa[x]][0] != x && child[fa[x]][1] != x;
}
inline void Reverse(int x) { swap(child[x][0], child[x][1]), r[x] ^= 1; }
inline void Pushdown(int x) {
  if (r[x]) {
    if (child[x][0]) Reverse(child[x][0]);
    if (child[x][1]) Reverse(child[x][1]);
    r[x] = 0;
  }
}
inline void Rotate(int x) {
  int f = fa[x], g = fa[f], c = child[f][1] == x;
  if (!Isroot(f)) child[g][child[g][1] == f] = x;
  child[f][c] = child[x][!c];
  child[x][!c] = f;
  if (child[f][c]) fa[child[f][c]] = f;
  fa[x] = g;
  fa[f] = x;
  Update(f);
}
inline void Splay(int x) {
  int y = x;
  top = 0;
  stk[++top] = y;
  while (!Isroot(y)) stk[++top] = y = fa[y];
  while (top) Pushdown(stk[top--]);
  while (!Isroot(x)) {
    y = fa[x];
    if (!Isroot(y))
      Rotate((child[y][0] == x) == (child[fa[y]][0] == y) ? y : x);
    Rotate(x);
  }
  Update(x);
}
inline void Access(int x) {
  for (register int y = 0; x; y = x, x = fa[x])
    Splay(x), Esize[x] += Rsize[child[x][1]], Esize[x] -= Rsize[y],
        child[x][1] = y, Update(x);
}
inline void Makeroot(int x) { Access(x), Splay(x), Reverse(x); }
inline bool Unicom(int x, int y) {
  Makeroot(x), Access(y), Splay(y);
  int k = y;
  while (child[k][0]) k = child[k][0];
  return k == x;
}
inline void Link(int x, int y) {
  Makeroot(x), Splay(x);
  fa[x] = y, Esize[y] += Rsize[x];
}
inline void Cut(int x, int y) {
  Makeroot(x), Access(y), Splay(y);
  child[y][0] = fa[x] = 0;
  Update(y);
}
int main() {
  int n, m, ans;
  read(n), read(m);
  for (register int i = 1; i <= n; ++i) read(a[i]);
  for (register int i = 1; i <= m; ++i)
    read(e[i].x), read(e[i].y), read(e[i].val);
  sort(e + 1, e + 1 + m, cmp);
  for (register int i = 1; i <= m; ++i) {
    if (Unicom(e[i].x, e[i].y)) continue;
    Link(e[i].x, e[i].y), vis[i] = 1;
  }
  for (register int i = m; i; --i)
    if (vis[i]) {
      Makeroot(e[i].x), Splay(e[i].x);
      if (Rsize[e[i].x] < e[i].val) Cut(e[i].x, e[i].y);
    }
  for (register int i = 1; i <= m; ++i)
    if (!Unicom(e[i].x, e[i].y))
      ++ans;
    else {
      Makeroot(e[i].x), Splay(e[i].x);
      if (Rsize[e[i].x] < e[i].val) ++ans;
    }
  printf("%d\n", ans);
  return 0;
}
