#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3fffffff;
const long long int INF = 0x3fffffffffffffff;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int n, m, cnt[100010] = {};
long long int X[100010] = {};
template <class Abel>
struct UnionFind {
  vector<int> par, rank;
  vector<Abel> diff_weight;
  UnionFind(int n = 1, Abel SUM_UNITY = 0) { init(n, SUM_UNITY); }
  void init(int n = 1, Abel SUM_UNITY = 0) {
    par.resize(n);
    rank.resize(n);
    diff_weight.resize(n);
    for (int i = (0); i < (n); i++)
      par[i] = -1, rank[i] = 0, diff_weight[i] = SUM_UNITY;
  }
  int root(int x) {
    if (par[x] < 0) return x;
    int r = root(par[x]);
    diff_weight[x] += diff_weight[par[x]];
    return par[x] = r;
  }
  int size(int x) { return -par[root(x)]; }
  Abel weight(int x) {
    root(x);
    return diff_weight[x];
  }
  bool issame(int x, int y) { return root(x) == root(y); }
  bool merge(int x, int y, Abel w) {
    w += weight(x) - weight(y);
    x = root(x);
    y = root(y);
    if (x == y) {
      cnt[x]++;
      return false;
    }
    if (rank[x] < rank[y]) swap(x, y), w = -w;
    if (rank[x] == rank[y]) ++rank[x];
    cnt[x] += cnt[y] + 1;
    X[x] += X[y];
    par[x] += par[y];
    par[y] = x;
    diff_weight[y] = w;
    return true;
  }
  Abel diff(int x, int y) { return weight(y) - weight(x); }
};
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (0); i < (n); i++) scanf("%lld", &X[i]);
  vector<pair<int, pair<int, int>>> es(m);
  for (int i = (0); i < (m); i++) {
    scanf("%d%d%d", &es[i].second.first, &es[i].second.second, &es[i].first);
    es[i].second.first--;
    es[i].second.second--;
  }
  sort((es).begin(), (es).end());
  int dec = 0;
  UnionFind<int> uni(n);
  for (int i = (0); i < (m); i++) {
    int u = uni.root(es[i].second.first), v = uni.root(es[i].second.second),
        w = es[i].first;
    uni.merge(u, v, 1);
    if (X[u] >= w) dec += cnt[u], cnt[u] = 0;
  }
  printf("%d\n", m - dec);
  return 0;
}
