#include <bits/stdc++.h>
using namespace std;
template <int um>
class UF_pop {
 public:
  vector<int> par, rank;
  vector<int> tot;
  vector<vector<signed long long>> hist;
  UF_pop() {
    par = rank = vector<int>(um, 0);
    tot = vector<int>(um, 0);
    for (int i = 0; i < um; i++) par[i] = i;
  }
  int operator[](int x) { return (par[x] == x) ? (x) : operator[](par[x]); }
  void pop() {
    if (hist.size()) {
      auto a = hist.back();
      hist.pop_back();
      par[a[0]] = a[1];
      rank[a[0]] = a[2];
      par[a[3]] = a[4];
      rank[a[3]] = a[5];
      tot[a[0]] = a[6];
      tot[a[3]] = a[7];
    }
  }
  void operator()(int x, int y, int id) {
    x = operator[](x);
    y = operator[](y);
    hist.push_back(
        {x, par[x], rank[x], y, par[y], rank[y], tot[x], tot[y], id});
    if (x == y) return;
    tot[x] = tot[y] = tot[x] + tot[y];
    if (rank[x] < rank[y])
      par[x] = y;
    else
      rank[x] += (rank[x] == rank[y]), par[y] = x;
  }
};
UF_pop<500000> uf;
int N, M;
signed long long X[101010];
int A[101010], B[101010];
signed long long Y[101010];
pair<signed long long, int> P[101010];
int ok[101010];
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  cin >> N >> M;
  for (i = 0; i < (N); i++) {
    cin >> X[i];
    uf.tot[i] = X[i];
  }
  for (i = 0; i < (M); i++) {
    cin >> A[i] >> B[i] >> Y[i];
    A[i]--;
    B[i]--;
    P[i] = {Y[i], i};
  }
  sort(P, P + M);
  for (i = 0; i < (M); i++) {
    x = P[i].second;
    if (uf[A[x]] != uf[B[x]]) {
      uf(A[x], B[x], x);
    }
  }
  while (uf.hist.size()) {
    x = uf[uf.hist.back()[0]];
    int id = uf.hist.back().back();
    if (uf.tot[x] >= Y[id]) {
      ok[id] = 1;
      uf.hist.back()[6] = uf.hist.back()[7] = uf.tot[x];
    } else {
      ok[id] = -1;
    }
    uf.pop();
  }
  for (i = 0; i < (N); i++) uf.tot[i] = X[i];
  int ret = 0;
  for (i = 0; i < (M); i++) {
    x = P[i].second;
    if (ok[x] == 1) {
      uf(A[x], B[x], x);
    } else if (ok[x] == -1) {
      ret++;
    } else if (uf[A[x]] != uf[B[x]]) {
      ret++;
    } else if (uf.tot[uf[A[x]]] < Y[x]) {
      ret++;
    }
  }
  cout << ret << endl;
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
  for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
  cout.tie(0);
  solve();
  return 0;
}
