#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<long long> X;
vector<long long> E;
vector<map<int, int>> G;
int ans = 0;
vector<int> a;
vector<bool> fix;
vector<bool> used;
long long ss, mm;
void f(int v, int id, long long limit) {
  if (a[v] == id) return;
  a[v] = id;
  ss += X[v];
  for (auto it = G[v].begin(); it != G[v].end();) {
    if (E[it->second] <= limit) {
      mm = max(mm, E[it->second]);
      f(it->first, id, limit);
      ++it;
    } else {
      G[it->first].erase(v);
      G[v].erase(it++);
    }
  }
}
void g(int v, int id, long long limit) {
  if (a[v] == id) return;
  a[v] = id;
  fix[v] = true;
  for (auto p : G[v]) {
    if (E[p.second] <= limit) {
      used[p.second] = true;
      g(p.first, id, limit);
    }
  }
}
int main() {
  cin >> N >> M;
  X = vector<long long>(N);
  E = vector<long long>(M);
  G.resize(N);
  long long sum = 0;
  for (int i = 0; i < N; ++i) {
    cin >> X[i];
    sum += X[i];
  }
  for (int i = 0; i < M; ++i) {
    int u, v;
    cin >> u >> v >> E[i];
    --u;
    --v;
    G[u][v] = i;
    G[v][u] = i;
  }
  int id = 0;
  a.resize(N);
  fix.resize(N);
  used.resize(M);
  for (int i = 0; i < N; ++i)
    if (!fix[i]) {
      auto limit = sum;
      for (;;) {
        ss = 0;
        mm = 0;
        f(i, ++id, limit);
        if (mm <= ss) break;
        limit = ss;
      }
      sum -= ss;
      g(i, ++id, limit);
    }
  int res = 0;
  for (auto x : used)
    if (!x) ++res;
  cout << res << endl;
}
