#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &x, T y) {
  return (y < x) ? (x = y, 1) : 0;
}
template <typename T>
inline bool chkmax(T &x, T y) {
  return (y > x) ? (x = y, 1) : 0;
}
inline int read() {
  int x;
  char c;
  int f = 1;
  while ((c = getchar()) != '-' && (c > '9' || c < '0'))
    ;
  if (c == '-') f = -1, c = getchar();
  x = c ^ '0';
  while ((c = getchar()) >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + (c ^ '0');
  return x * f;
}
inline long long readll() {
  long long x;
  char c;
  int f = 1;
  while ((c = getchar()) != '-' && (c > '9' || c < '0'))
    ;
  if (c == '-') f = -1, c = getchar();
  x = c ^ '0';
  while ((c = getchar()) >= '0' && c <= '9')
    x = (x << 1ll) + (x << 3ll) + (c ^ '0');
  return x * f;
}
const int maxn = 1e5 + 10;
struct point {
  int x, y, z;
  bool operator<(const point &rhs) const { return z < rhs.z; }
} b[maxn];
int a[maxn], fa[maxn], sum[maxn], tot[maxn];
int find(int x) {
  if (fa[x] == x) return x;
  return fa[x] = find(fa[x]);
}
int main() {
  int n = read(), m = read();
  for (register int i = 1, iend = n; i <= iend; ++i) fa[i] = i, tot[i] = read();
  for (register int i = 1, iend = m; i <= iend; ++i)
    b[i].x = read(), b[i].y = read(), b[i].z = read();
  sort(b + 1, b + m + 1);
  for (register int i = 1, iend = m; i <= iend; ++i) {
    int x = b[i].x, y = b[i].y, z = b[i].z;
    x = find(x), y = find(y);
    if (x == y)
      sum[x] += (z > tot[x]);
    else {
      fa[x] = y, tot[y] += tot[x], sum[y] += sum[x];
      if (z > tot[y])
        sum[y]++;
      else
        sum[y] = 0;
    }
  }
  int ans = 0;
  for (register int i = 1, iend = n; i <= iend; ++i)
    if (fa[i] == i) ans += sum[i];
  printf("%d\n", ans);
  return 0;
}
