#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  long long X[100001];
  vector<pair<long long, long long>> edge[100001];
  set<pair<long long, long long>> removed, checked;
  cin >> N >> M;
  for (int i = 1; i <= N; i++) {
    cin >> X[i];
  }
  for (int i = 1; i <= M; i++) {
    long long A, B, Y;
    cin >> A >> B >> Y;
    edge[A].push_back({Y, B});
    edge[B].push_back({Y, A});
  }
  for (int i = 1; i <= N; i++) sort(edge[i].begin(), edge[i].end());
  bool flg;
  long long ans = 0;
  do {
    flg = true;
    checked.clear();
    for (int i = 1; i <= N; i++) {
      for (auto e : edge[i]) {
        if (removed.count({i, e.second})) continue;
        if (checked.count(e) > 0) continue;
        long long sum = X[e.first] + X[e.second];
        queue<int> Q;
        Q.push(e.first);
        Q.push(e.second);
        unordered_set<long long> chk;
        chk.insert(e.first);
        chk.insert(e.second);
        while (!Q.empty()) {
          auto t = Q.front();
          Q.pop();
          for (auto ed : edge[t]) {
            if (removed.count({t, ed.second})) continue;
            if (chk.count(ed.second) == 0) {
              chk.insert(ed.second);
              Q.push(ed.second);
              sum += X[ed.second];
            }
          }
        }
        for (auto x : chk) {
          for (auto ed : edge[x]) {
            if (removed.count({x, ed.second})) continue;
            if (ed.first > sum) {
              removed.insert(make_pair(x, ed.second));
              ans++;
            }
          }
        }
      }
    }
  } while (!flg);
  cout << ans / 2 << endl;
  return 0;
}
