#include <bits/stdc++.h>
using namespace std;
int a[100010];
vector<pair<int, int> > from[100010];
vector<pair<int, pair<int, int> > > edge;
int fa[100010];
long long val[100010];
int vis[100010];
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    fa[i] = i, val[i] = a[i], sum += a[i];
  }
  int ans = 0;
  int flag = 0;
  for (int i = 0; i < m; i++) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, &c);
    from[u].push_back(make_pair(v, c));
    from[v].push_back(make_pair(u, c));
    edge.push_back(make_pair(c, make_pair(u, v)));
    if (sum < c) ans++, vis[i] = 1, flag = 1;
  }
  while (flag) {
    flag = 0;
    for (int i = 1; i <= n; i++) {
      fa[i] = i, val[i] = a[i];
    }
    for (int i = 0; i < m; i++) {
      if (vis[i]) continue;
      int u = edge[i].second.first, v = edge[i].second.second;
      if (find(u) == find(v)) continue;
      val[find(v)] += val[find(u)], fa[find(u)] = find(v);
    }
    for (int i = 0; i < m; i++) {
      if (vis[i]) continue;
      int u = edge[i].second.first, v = edge[i].second.second;
      if (val[find(u)] < edge[i].first) ans++, vis[i] = 1, flag = 1;
    }
  }
  printf("%d\n", ans);
  return 0;
}
