#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n, m, v[maxn];
bool flag[maxn];
struct P {
  int x, y, val;
  P() {}
  bool operator<(const P& a) const { return val < a.val; }
} e[maxn];
int fa[maxn];
long long sum[maxn], ve[maxn];
int pd(int x) {
  if (x != fa[x]) fa[x] = pd(fa[x]);
  return fa[x];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &v[i]);
  for (int i = 1; i <= n; i++) {
    fa[i] = i;
    sum[i] = v[i];
  }
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &e[i].x, &e[i].y, &e[i].val);
  }
  sort(e, e + m);
  int ret = 0;
  for (int i = 0; i < m; i++) {
    int fx = pd(e[i].x);
    int fy = pd(e[i].y);
    if (fx != fy) {
      fa[fx] = fy;
      sum[fy] += sum[fx];
      sum[fx] = 0;
    }
    ve[i] = sum[fy];
  }
  for (int i = m - 1; i >= 0; i--) {
    int faaa = pd(e[i].x);
    if (flag[faaa]) continue;
    if (ve[i] < e[i].val) {
      ret++;
    } else {
      flag[faaa] = 1;
    }
  }
  cout << ret << endl;
  return 0;
}
