#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

struct UnionFind {
  vector<int> parent;  // parent[root] is the negative of the size.
  UnionFind(int n)
      : parent(n, -1){};
  bool unite(int u, int v) {
    u = root(u);
    v = root(v);
    if (u == v) return false;
    if (parent[u] > parent[v]) swap(u, v);
    parent[u] += parent[v];
    parent[v] = u;
    return true;
  }
  bool find(int u, int v) {
    return root(u) == root(v);
  }
  int root(int u) {
    return parent[u] < 0 ? u : parent[u] = root(parent[u]);
  }
  int size(int u) {
    return -parent[root(u)];
  }
};

int main() {
  int N, M;
  while (cin >> N >> M) {
    vector<ll> X(N);
    for (int i = 0; i < N; i++) cin >> X[i];
    vector<ll> A(M), B(M), Y(M);
    for (int i = 0; i < M; i++) {
      cin >> A[i] >> B[i] >> Y[i];
      --A[i];
      --B[i];
    }
    int res = 0;
    vector<int> removed(M, false);
    for (;;) {
      UnionFind uf(N);
      for (int i = 0; i < M; i++) {
        if (!removed[i]) {
          uf.unite(A[i], B[i]);
        }
      }
      vector<ll> sum(N, 0);
      for (int v = 0; v < N; v++) sum[uf.root(v)] += X[v];
      bool ok = true;
      for (int i = 0; i < M; i++) {
        if (removed[i]) continue;
        if (sum[uf.root(A[i])] < Y[i]) {
          ok = false;
          ++res;
          removed[i] = true;
        }
      }
      if (ok) break;
    }
    cout << res << endl;
  }
  return 0;
}
