#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const long long int linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef struct UnionFind_ {
  vector<int> par;
  vector<int> rank_;
  vector<long long int> w;
  UnionFind_(int n) : rank_(n, 0), w(n, 0) {
    for (int i = 0; i < n; i++) par.push_back(i);
  }
  int find(int x) {
    if (par[x] == x)
      return x;
    else
      return par[x] = find(par[x]);
  }
  bool same(int x, int y) {
    if (find(x) == find(y))
      return true;
    else
      return false;
  }
  bool unite(int x, int y) {
    int xp = find(x);
    int yp = find(y);
    if (xp == yp) return false;
    if (rank_[xp] > rank_[yp]) {
      par[yp] = xp;
      w[xp] += w[yp];
    } else if (rank_[xp] < rank_[yp]) {
      par[xp] = yp;
      w[yp] += w[xp];
    } else {
      par[yp] = xp;
      rank_[xp]++;
      w[xp] += w[yp];
    }
    return true;
  }
} UnionFind;
struct edge {
  int from;
  int to;
  long long int cost;
};
bool comp(const edge &a, const edge &b) { return a.cost < b.cost; }
int main(int argc, char const *argv[]) {
  int n, m;
  cin >> n >> m;
  vector<long long int> x(n);
  UnionFind uf(n);
  for (int i = (0); i < (n); ++i) cin >> x[i];
  for (int i = (0); i < (n); ++i) uf.w[i] = x[i];
  vector<edge> vec;
  for (int i = (0); i < (m); ++i) {
    int a, b;
    long long int y;
    cin >> a >> b >> y;
    a--;
    b--;
    if (x[a] + x[b] <= y)
      uf.unite(a, b);
    else
      vec.push_back((edge){a, b, y});
  }
  int res = 0;
  sort((vec).begin(), (vec).end(), comp);
  for (int i_t = 0; i_t < 1000; i_t++) {
    bool update = false;
    for (int i = (0); i < (((int)(vec).size())); ++i) {
      int from = vec[i].from;
      int to = vec[i].to;
      long long int cost = vec[i].cost;
      if (!uf.same(from, to) &&
          uf.w[uf.find(from)] + uf.w[uf.find(to)] >= cost) {
        uf.unite(from, to);
        update = true;
      }
    }
    if (!update) break;
  }
  for (int i = (0); i < (((int)(vec).size())); ++i) {
    int from = vec[i].from;
    int to = vec[i].to;
    if (uf.find(from) != uf.find(to)) res++;
  }
  cout << res << endl;
  return 0;
}
