#include <bits/stdc++.h>
using namespace std;
int N, M;
int X[100010];
int flg[100010];
int SUM[200010];
vector<int> path[100010];
map<pair<int, int>, int> dame;
int cnt = 0;
int main() {
  int rem = 0;
  priority_queue<pair<int, pair<int, int> > > PQ;
  cin >> N >> M;
  for (int i = 1; i <= N; i++) {
    cin >> X[i];
    SUM[0] += X[i];
  }
  for (int i = 1; i <= M; i++) {
    int a, b, y;
    cin >> a >> b >> y;
    path[a].push_back(b);
    path[b].push_back(a);
    PQ.push(pair<int, pair<int, int> >(y, pair<int, int>(a, b)));
  }
  while (!PQ.empty()) {
    int line = PQ.top().first;
    int a = PQ.top().second.first;
    int b = PQ.top().second.second;
    PQ.pop();
    if (SUM[flg[a]] >= line) continue;
    rem++;
    dame[pair<int, int>(a, b)] = 1;
    dame[pair<int, int>(b, a)] = 1;
    cnt++;
    queue<int> Q;
    Q.push(a);
    flg[a] = cnt;
    while (!Q.empty()) {
      int id = Q.front();
      Q.pop();
      SUM[cnt] += X[id];
      for (int i = 0; i < path[id].size(); i++) {
        int nxt = path[id][i];
        if (dame[pair<int, int>(id, nxt)]) continue;
        if (flg[nxt] != cnt) {
          flg[nxt] = cnt;
          Q.push(nxt);
        }
      }
    }
    if (flg[b] == cnt) continue;
    cnt++;
    Q.push(b);
    flg[b] = cnt;
    while (!Q.empty()) {
      int id = Q.front();
      Q.pop();
      SUM[cnt] += X[id];
      for (int i = 0; i < path[id].size(); i++) {
        int nxt = path[id][i];
        if (dame[pair<int, int>(id, nxt)]) continue;
        if (flg[nxt] != cnt) {
          flg[nxt] = cnt;
          Q.push(nxt);
        }
      }
    }
  }
  cout << rem << endl;
  return 0;
}
