#include <bits/stdc++.h>
using namespace std;
long long int parent[505050];
long long int n, m;
long long int x[101010];
pair<long long int, pair<long long int, long long int> > links[101010];
bool use[101010];
long long int lim[101010];
inline void init_uf() {
  for (long long int i = 0; i < ((long long int)(505050)); i++) parent[i] = i;
}
inline long long int find(long long int x) {
  if (parent[x] == x)
    return x;
  else
    return (parent[x] = find(parent[x]));
}
inline void union_(long long int x, long long int y) {
  long long int parent_x = find(x);
  long long int parent_y = find(y);
  parent[parent_x] = parent_y;
}
int main() {
  cin >> n >> m;
  long long int sum = 0;
  for (long long int i = 0; i < ((long long int)(n)); i++) {
    cin >> x[i];
    sum += x[i];
  }
  for (long long int i = 0; i < ((long long int)(n)); i++) {
    lim[i] = sum;
  }
  for (long long int i = 0; i < ((long long int)(m)); i++) {
    long long int a, b, y;
    cin >> a >> b >> y;
    a--;
    b--;
    links[i] = {y, {a, b}};
    use[i] = true;
  }
  sort(links, links + m);
  long long int res = 0;
  while (true) {
    long long int prev_res = res;
    {
      init_uf();
      for (long long int i = 0; i < ((long long int)(m)); i++) {
        if (!use[i]) continue;
        long long int w = links[i].first;
        if (w > lim[links[i].second.first] || w > lim[links[i].second.first]) {
          ++res;
          use[i] = false;
          continue;
        }
        union_(links[i].second.first, links[i].second.second);
      }
    }
    {
      map<long long int, long long int> group_size;
      for (long long int i = 0; i < ((long long int)(n)); i++) {
        group_size[find(i)] += x[i];
      }
      for (long long int i = 0; i < ((long long int)(n)); i++) {
        lim[i] = group_size[find(i)];
      }
    }
    if (res == prev_res) break;
  }
  cout << res << endl;
  return 0;
}
