#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
struct edge {
  int a, b, c;
  void input() { scanf("%d%d%d", &a, &b, &c); }
  bool operator<(const edge &rhs) const { return c < rhs.c; }
};
int N, M;
set<pair<int, int> > adj[MAXN];
int x[MAXN];
edge e[MAXN];
bool ok[MAXN], taken[MAXN];
int dad[MAXN], rnk[MAXN];
long long sum[MAXN];
bool bio[MAXN];
void load() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= N; i++) scanf("%d", x + i);
  for (int i = 0; i < M; i++) e[i].input();
}
int find(int x) { return dad[x] == x ? x : dad[x] = find(dad[x]); }
void join(int u, int v) {
  u = find(u);
  v = find(v);
  if (u == v) return;
  if (rnk[u] > rnk[v]) swap(u, v);
  dad[u] = v;
  rnk[v] += rnk[u] == rnk[v];
  sum[v] += sum[u];
}
void dfs(int x) {
  bio[x] = true;
  for (auto it : adj[x])
    if (!bio[it.first]) {
      ok[it.second] = true;
      dfs(it.first);
    }
}
int solve() {
  sort(e, e + M);
  for (int i = 1; i <= N; i++) {
    dad[i] = i;
    sum[i] = x[i];
  }
  int ptr = 0;
  for (int i = 0; i < M;) {
    for (; ptr < M && e[ptr].c == e[i].c; ptr++) join(e[ptr].a, e[ptr].b);
    for (int j = i; j < ptr; j++) taken[j] = sum[find(e[j].a)] < e[j].c;
    i = ptr;
  }
  for (int i = 0; i < M; i++) {
    adj[e[i].a].insert({e[i].b, i});
    adj[e[i].b].insert({e[i].a, i});
  }
  int sol = 0;
  for (int i = M - 1; i >= 0; i--) {
    if (ok[i]) continue;
    if (taken[i]) {
      adj[e[i].a].erase({e[i].b, i});
      adj[e[i].b].erase({e[i].a, i});
      sol++;
      continue;
    }
    dfs(e[i].a);
  }
  return sol;
}
int main() {
  load();
  printf("%d\n", solve());
  return 0;
}
