#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},
                         {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};
int n, m;
long long x[100010];
int a[100010], b[100010];
long long y[100010];
struct UF {
  int par[100010], r[100010];
  long long par_cost[100010];
  long long cnt[100010];
  long long ret[100010];
  void init() {
    for (int i = 0; i < 100010; i++) {
      par[i] = i;
      r[i] = 0;
      par_cost[i] = 0;
      cnt[i] = 1;
      ret[i] = i;
    }
  }
  int find(int x) {
    if (par[x] == x)
      return par[x];
    else
      find(par[x]);
  }
  bool same(int x, int y) { return find(x) == find(y); }
  void unit(int x, int y, long long c) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (r[x] < r[y]) {
      par[x] = y;
      par_cost[x] = c;
      cnt[y] += cnt[x];
    } else {
      par[y] = x;
      par_cost[y] = c;
      cnt[x] += cnt[y];
      if (r[x] == r[y]) {
        r[x]++;
      }
    }
  }
  bool used[100010];
  void dfs_init() {
    for (int i = 0; i < 100010; i++) {
      used[i] = false;
    }
  }
  void dfs(int v) {
    used[v] = true;
    if (!used[par[v]]) dfs(par[v]);
    if (par_cost[v] <= ret[par[v]]) {
      ret[v] = ret[par[v]];
    }
  }
} uf;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%lld", &x[i]);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%lld", &a[i], &b[i], &y[i]);
  }
  uf.init();
  for (int i = 1; i <= n; i++) {
    uf.cnt[i] = x[i];
  }
  vector<pair<long long, pair<long long, long long>>> vec;
  for (int i = 1; i <= m; i++) {
    vec.push_back(pair<long long, pair<long long, long long>>(
        y[i], pair<long long, long long>(a[i], b[i])));
  }
  sort(vec.begin(), vec.end());
  for (int i = 0; i < vec.size(); i++) {
    pair<long long, pair<long long, long long>> p = vec[i];
    int s = uf.find(p.second.first);
    int t = uf.find(p.second.second);
    if (s == t) continue;
    uf.unit(s, t, p.first);
    if (uf.par[s] == t) swap(s, t);
    if (uf.cnt[s] >= p.first) {
      uf.ret[s] = uf.cnt[s];
      uf.ret[t] = uf.cnt[s];
    }
  }
  uf.dfs_init();
  for (int i = 1; i <= n; i++) uf.dfs(i);
  long long ret = 0;
  for (int i = 1; i <= m; i++) {
    if (uf.ret[a[i]] < y[i]) ret++;
  }
  cout << ret << endl;
}
