#include <bits/stdc++.h>
using namespace std;
int N, M;
int X[100010];
vector<int> path[100010];
vector<pair<int, pair<int, int> > > edge;
map<pair<int, int>, int> dame;
int removed = 0;
int main() {
  cin >> N >> M;
  for (int i = 1; i <= N; i++) cin >> 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);
    edge.push_back(pair<int, pair<int, int> >(y, pair<int, int>(a, b)));
  }
  sort(edge.begin(), edge.end());
  reverse(edge.begin(), edge.end());
  for (int i = 0; i < edge.size(); i++) {
    int line = edge[i].first;
    int a = edge[i].second.first;
    int b = edge[i].second.second;
    vector<int> flg(N + 1, 0);
    int sum = 0;
    queue<int> Q;
    Q.push(a);
    flg[a] = 1;
    while (!Q.empty()) {
      int id = Q.front();
      Q.pop();
      sum += X[id];
      for (int j = 0; j < path[id].size(); j++) {
        int nxt = path[id][j];
        if (dame[pair<int, int>(id, nxt)]) continue;
        if (flg[nxt] == 0) {
          flg[nxt] = 1;
          Q.push(nxt);
        }
      }
    }
    if (sum < line) {
      removed++;
      dame[pair<int, int>(a, b)] = 1;
      dame[pair<int, int>(b, a)] = 1;
    }
  }
  cout << removed << endl;
  return 0;
}
