#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e6 + 10;
int x[N], p[N], cnt_bad, n, m, good, last = -1;
long long sum[N];
bool bad[N];
int getp(int v) { return (v == p[v]) ? v : (p[v] = getp(p[v])); }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &x[i]);
    p[i] = i;
    sum[i] = x[i];
  }
  vector<pair<int, pair<int, int> > > e(m);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d", &e[i].second.first, &e[i].second.second, &e[i].first);
    --e[i].second.first, --e[i].second.second;
  }
  sort(e.begin(), e.end());
  for (int i = 0; i < m; ++i) {
    int u = getp(e[i].second.first), v = getp(e[i].second.second),
        w = e[i].first;
    if (u == v) continue;
    if (bad[u]) bad[u] = false, --cnt_bad;
    if (bad[v]) bad[v] = false, --cnt_bad;
    sum[u] += sum[v], p[v] = u;
    if (w > sum[u]) bad[u] = true, ++cnt_bad;
    if (cnt_bad == 0) last = i;
  }
  for (int i = 0; i < n; ++i) {
    p[i] = i;
    sum[i] = x[i];
  }
  for (int i = 0; i <= last; ++i) {
    int u = getp(e[i].second.first), v = getp(e[i].second.second);
    if (u == v) continue;
    p[v] = u, sum[u] += sum[v];
  }
  for (int i = 0; i < m; ++i) {
    int u = getp(e[i].second.first), v = getp(e[i].second.second),
        w = e[i].first;
    if (u != v) continue;
    if (w <= sum[u]) good++;
  }
  printf("%d\n", m - good);
  return 0;
}
