#include <bits/stdc++.h>
using namespace std;
int N, M;
long long X[100000];
vector<pair<pair<long long, int>, pair<int, int> > > hen;
bool ok[100000] = {};
vector<pair<int, int> > tonari[100000];
int G = 1;
int groupN[100000], groupE[100000];
long long groupS[100000];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> X[i];
    groupN[i] = 0;
    groupS[0] += X[i];
  }
  int ans = 0;
  for (int i = 0; i < M; i++) {
    int a, b, y;
    cin >> a >> b >> y;
    if (y > groupS[0]) {
      ans++;
      i--;
      M--;
      continue;
    }
    a--;
    b--;
    hen.push_back(make_pair(make_pair(y, i), make_pair(a, b)));
    tonari[a].push_back(make_pair(b, i));
    tonari[b].push_back(make_pair(a, i));
    ok[i] = true;
    groupE[i] = 0;
  }
  sort(hen.begin(), hen.end());
  reverse(hen.begin(), hen.end());
  for (int i = 0; i < hen.size(); i++) {
    queue<int> que;
    que.push(hen[i].second.first);
    int sum = X[hen[i].second.first];
    bool already[100000] = {};
    already[hen[i].second.first] = true;
    while (!que.empty()) {
      int now = que.front();
      que.pop();
      for (int i = 0; i < tonari[now].size(); i++) {
        if (ok[tonari[now][i].second] && !already[tonari[now][i].first]) {
          already[tonari[now][i].first] = true;
          sum += X[tonari[now][i].first];
          if (sum >= hen[i].first.first) break;
          que.push(tonari[now][i].first);
        }
      }
    }
    if (sum < hen[i].first.first) {
      ans++;
      ok[hen[i].first.second] = false;
    }
  }
  cout << ans << endl;
  return 0;
}
