#include <bits/stdc++.h>
using namespace std;
using vint = vector<long long>;
using vvint = vector<vint>;
using pint = pair<long long, long long>;
using vpint = vector<pint>;
template <typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double pi = 3.1415926535897932384626433832795028;
constexpr long long dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr long long dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
long long gcd(long long a, long long b) {
  while (b) {
    swap(a %= b, b);
  }
  return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
  os << "(" << rhs.first << ", " << rhs.second << ")";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &rhs) {
  os << "{";
  for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
    os << *itr << (next(itr) != rhs.end() ? ", " : "");
  }
  os << "}";
  return os;
}
struct setup {
  static constexpr long long PREC = 20;
  setup() {
    cout << fixed << setprecision(PREC);
    cerr << fixed << setprecision(PREC);
  };
} setup;
struct union_find_tree {
  long long n;
  std::vector<long long> par, size;
  vint last_edge, weight_sum;
  union_find_tree(long long n)
      : n(n), par(n), size(n), last_edge(n), weight_sum(n) {
    for (long long i = 0; i < n; i++) {
      par[i] = i;
      size[i] = 1;
      last_edge[i] = -1;
    }
  }
  long long get_root(long long i) {
    if (par[i] == i) {
      return i;
    } else {
      return par[i] = get_root(par[i]);
    }
  }
  void unite(long long i, long long j, long long edge) {
    if ((i = get_root(i)) == (j = get_root(j))) {
      return;
    }
    if (size[i] < size[j]) {
      std::swap(i, j);
    }
    par[j] = i;
    last_edge[i] = edge;
    weight_sum[i] += weight_sum[j];
    size[i] += size[j];
  }
  bool are_same(long long i, long long j) { return get_root(i) == get_root(j); }
  long long get_size(long long i) { return size[get_root(i)]; }
};
long long N, M;
long long X[110000];
long long A[110000], B[110000], Y[110000];
pair<long long, pint> edges[110000];
vint edge_tree[110000];
bool prev_ok[110000], final_ok[110000];
void dfs(long long idx) {
  if (idx == -1) {
    return;
  }
  if (prev_ok[idx]) {
    return;
  }
  final_ok[idx] = false;
  for (long long i = 0; i < (edge_tree[idx].size()); i++) {
    dfs(edge_tree[idx][i]);
  }
}
signed main() {
  cin >> N >> M;
  for (long long i = 1; i <= (N); i++) {
    cin >> X[i];
  }
  for (long long i = 0; i < (M); i++) {
    cin >> A[i] >> B[i] >> Y[i];
    edges[i] = {Y[i], {A[i], B[i]}};
  }
  union_find_tree uft0(N + 1);
  for (long long i = 1; i <= (N); i++) {
    uft0.weight_sum[i] = X[i];
  }
  sort(edges, edges + M);
  long long le;
  for (long long i = 0; i < (M); i++) {
    long long a = edges[i].second.first, b = edges[i].second.second,
              y = edges[i].first;
    a = uft0.get_root(a), b = uft0.get_root(b);
    if (uft0.are_same(a, b)) {
      continue;
    }
    le = i;
    final_ok[i] = true;
    edge_tree[i].push_back(uft0.last_edge[a]);
    edge_tree[i].push_back(uft0.last_edge[b]);
    prev_ok[i] = y <= uft0.weight_sum[a] + uft0.weight_sum[b];
    uft0.unite(a, b, i);
  }
  dfs(le);
  union_find_tree uft1(N + 1);
  for (long long i = 1; i <= (N); i++) {
    uft1.weight_sum[i] = X[i];
  }
  for (long long i = 0; i < (M); i++) {
    long long a = edges[i].second.first, b = edges[i].second.second;
    if (final_ok[i]) {
      uft1.unite(a, b, i);
    }
  }
  long long ans = M;
  for (long long i = 0; i < (M); i++) {
    long long a = edges[i].second.first, y = edges[i].first;
    a = uft1.get_root(a);
    ans -= y <= uft1.weight_sum[a];
  }
  cout << ans << endl;
}
