#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using std::cin;
using std::cout;
using std::lower_bound;
using std::string;
using std::upper_bound;
using std::vector;
using vi = vector<long long>;
using vii = vector<vi>;
using pii = std::pair<long long, long long>;
constexpr long long MOD = 1e9 + 7;
constexpr long long MAX = 1e7;
constexpr long long INF = (1ll << 60);
template <class T>
class prique : public std::priority_queue<T, std::vector<T>, std::greater<T>> {
};
struct Binary_indexed_tree {
  int N;
  vi bit;
  Binary_indexed_tree(int n) : N(n) { bit.resize(N + 1, 0); }
  void add(int x, int a) {
    for (x; x <= N; x += (x & -x)) bit[x] += a;
  }
  long long sum(int x) {
    long long ret = 0;
    for (x; x > 0; x -= (x & -x)) ret += bit[x];
    return ret;
  }
  long long lower_bound(long long X) {
    if (sum(N) < X) return -1;
    long long ret = 0, memo = 1, sum = 0;
    while (memo * 2 <= N) memo *= 2;
    while (memo > 0) {
      if (memo + ret <= N && sum + bit[memo + ret] < X) {
        sum += bit[memo + ret];
        ret += memo;
      }
      memo /= 2;
    }
    return ret + 1;
  }
};
struct Union_Find {
  long long N;
  vi par;
  vi siz;
  Union_Find(int n) : N(n) {
    par.resize(N);
    siz.resize(N, 1);
    for (long long i = (long long)(0); i < (long long)(N); i++) par[i] = i;
  }
  long long root(long long X) {
    if (par[X] == X) return X;
    return par[X] = root(par[X]);
  }
  bool same(long long X, long long Y) { return root(X) == root(Y); }
  void unite(long long X, long long Y) {
    X = root(X);
    Y = root(Y);
    if (X == Y) return;
    par[X] = Y;
    siz[Y] += siz[X];
    siz[X] = 0;
  }
  long long size(long long X) { return siz[root(X)]; }
};
long long modpow(long long X, long long Y) {
  long long sum = X, cnt = 1;
  vi A;
  while (cnt <= Y) {
    A.emplace_back(sum);
    sum *= sum;
    sum %= MOD;
    cnt *= 2;
  }
  int M = A.size();
  long long ret = 1;
  for (long long i = (long long)(1); i <= (long long)(M); i++) {
    if (Y >= (1ll << M - i)) {
      Y -= (1ll << M - i);
      ret *= A[M - i];
      ret %= MOD;
    }
  }
  return ret;
}
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(long long n, long long r) {
  if (n < r || n < 0 || r < 0) return 0;
  return fac[n] * finv[r] % MOD * finv[n - r] % MOD;
}
signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  long long N, M;
  cin >> N >> M;
  vi A(N);
  for (long long i = (long long)(0); i < (long long)(N); i++) cin >> A[i];
  vector<vector<pii>> edge(N);
  for (long long i = (long long)(0); i < (long long)(M); i++) {
    long long X, Y, Z;
    cin >> X >> Y >> Z;
    edge[X - 1].emplace_back(std::make_pair(Y - 1, Z));
    edge[Y - 1].emplace_back(std::make_pair(X - 1, Z));
  }
  bool flag = 1;
  while (flag) {
    flag = 0;
    vector<bool> F(N, 1);
    for (long long i = (long long)(0); i < (long long)(N); i++) {
      if (F[i]) {
        std::queue<long long> que;
        long long sum = 0;
        F[i] = 0;
        que.push(i);
        vi memo;
        while (!que.empty()) {
          long long X = que.front();
          que.pop();
          sum += A[X];
          memo.emplace_back(X);
          for (long long j = (long long)(0); j < (long long)(edge[X].size());
               j++) {
            long long Y = edge[X][j].first;
            if (F[Y]) {
              F[Y] = 0;
              que.push(Y);
            }
          }
        }
        for (long long j = (long long)(0); j < (long long)(memo.size()); j++) {
          long long X = memo[j];
          long long k = 0;
          vi P;
          for (long long k = (long long)(0); k < (long long)(edge[X].size());
               k++) {
            long long Y = edge[X][k].second;
            if (Y > sum) {
              flag = 1;
              P.emplace_back(k);
            }
          }
          for (long long k = (long long)(P.size() - 1); (long long)(0) <= k;
               k--) {
            long long Y = P[k];
            std::swap(edge[X][Y], edge[X][edge[X].size() - 1]);
            edge[X].pop_back();
          }
        }
      }
    }
  }
  long long ans = 0;
  for (long long i = (long long)(0); i < (long long)(N); i++)
    ans += edge[i].size();
  ans /= 2;
  ans = M - ans;
  cout << ans << "\n";
}
