#include <bits/stdc++.h>
using namespace std;
long long n, m, x[100010], y[100010], cut[100010] = {}, ans = 0,
                                      visited[100010] = {};
vector<long long> v[100010], id[100010];
int main(void) {
  cin >> n >> m;
  for (int i = ((int)(1)); i <= ((int)(n)); i++) cin >> x[i];
  for (int i = ((int)(1)); i <= ((int)(m)); i++) {
    long long a, b, d;
    cin >> a >> b >> d;
    v[a].push_back(b);
    v[b].push_back(a);
    id[a].push_back(i);
    id[b].push_back(i);
    y[i] = d;
  }
  for (int abcdef = 0; abcdef < ((int)(m)); abcdef++) {
    long long d_ans = 0;
    for (int i = ((int)(1)); i <= ((int)(n)); i++)
      if (visited[i] == 1) visited[i] = 0;
    for (int i = ((int)(1)); i <= ((int)(n)); i++) {
      if (visited[i] == 0) {
        long long dd_ans = 0;
        long long sum = 0;
        vector<long long> c;
        queue<long long> Q;
        Q.push(i);
        visited[i] = 1;
        while (!Q.empty()) {
          long long p = Q.front();
          Q.pop();
          c.push_back(p);
          sum += x[p];
          for (int j = 0; j < ((int)(v[p].size())); j++) {
            long long q = v[p][j];
            if (visited[q] == 0 && cut[id[p][j]] == 0) {
              visited[q] = 1;
              Q.push(q);
            }
          }
        }
        for (int j = 0; j < ((int)(c.size())); j++) {
          long long p = c[j];
          for (int j = 0; j < ((int)(v[p].size())); j++) {
            if (cut[id[p][j]] == 0 && sum < y[id[p][j]]) {
              cut[id[p][j]] = 1;
              dd_ans++;
            }
          }
        }
        if (dd_ans == 0) {
          for (int j = 0; j < ((int)(c.size())); j++) {
            long long p = c[j];
            visited[p] = 2;
          }
        }
        d_ans += dd_ans;
      }
    }
    if (d_ans == 0) break;
    ans += d_ans;
  }
  cout << ans << endl;
  return 0;
}
