#include <bits/stdc++.h>
using namespace std;
struct Ed {
  int u, v, w;
  Ed() {}
  Ed(int u, int v, int w) : u(u), v(v), w(w) {}
  bool operator<(const Ed &rhs) const { return w < rhs.w; }
  bool operator>(const Ed &rhs) const { return rhs < *this; }
  bool operator<=(const Ed &rhs) const { return !(rhs < *this); }
  bool operator>=(const Ed &rhs) const { return !(*this < rhs); }
};
const int N = 200010;
int n, m;
int a[N], f[N * 2], ch[N * 2][2];
int rec[N];
long long s[N];
Ed e[N];
int tag[N];
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i <= m; ++i) scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
  sort(e + 1, e + m + 1);
  iota(f + 1, f + n * 2, 1);
  for (int i = 1; i <= n; ++i) s[i] = a[i];
  int cnt = n;
  for (int i = 1; i <= m; ++i) {
    int x = find(e[i].u), y = find(e[i].v);
    if (x != y) {
      ;
      int t = ++cnt;
      rec[i] = 1;
      f[x] = t;
      f[y] = t;
      ch[t][0] = x;
      ch[t][1] = y;
      if ((s[t] = s[x] + s[y]) < e[i].w)
        tag[t] = -1;
      else
        tag[t] = 1;
      ;
    }
  }
  for (int i = n * 2 - 1; i > n; --i) {
    tag[ch[i][0]] = max(tag[ch[i][0]], tag[i]);
    tag[ch[i][1]] = max(tag[ch[i][1]], tag[i]);
  }
  iota(f + 1, f + n + 1, 1);
  int ans = 0;
  cnt = n;
  for (int i = 1; i <= m; ++i) {
    int x = find(e[i].u), y = find(e[i].v);
    if (rec[i]) {
      if (tag[++cnt] == 1) {
        f[x] = y;
        s[y] += s[x];
      } else {
        ++ans;
        ;
      }
    } else if (x != y || s[x] < e[i].w) {
      ;
      ++ans;
    } else {
      ;
    }
  }
  printf("%d\n", ans);
  return 0;
}
