#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 10;
const long long oo = 1e18;
struct EDGE {
  long long u, v, cost;
} edge[N];
long long n, m;
long long vertex[N];
bool check[N], visit[N], ans[N];
pair<long long, long long> pr[N];
vector<pair<long long, long long> > eg[N];
long long find(long long u) {
  return (pr[u].first == u) ? u : (pr[u].first = find(pr[u].first));
}
void addeg(long long u, long long v) {
  long long nu = find(u), nv = find(v);
  if (nu == nv) return;
  pr[nu].first = nv;
  pr[nv].second += pr[nu].second;
}
bool cmp(const long long x, const long long y) {
  return edge[x].cost < edge[y].cost;
}
void findedge() {
  vector<long long> tmp;
  for (long long i = 1; i <= m; ++i) tmp.push_back(i);
  sort(tmp.begin(), tmp.end(), cmp);
  for (auto it : tmp) {
    long long nu = find(edge[it].u), nv = find(edge[it].v);
    if (nu == nv) {
      if (pr[nu].second >= edge[it].cost) check[it] = 1;
    } else {
      if (pr[nu].second + pr[nv].second >= edge[it].cost) check[it] = 1;
      addeg(nu, nv);
    }
  }
}
void dfs(long long u, long long cost) {
  visit[u] = 1;
  for (auto it : eg[u])
    if (edge[it.second].cost <= cost) {
      ans[it.second] = 1;
      if (!visit[it.first]) dfs(it.first, cost);
    }
}
void spread() {
  vector<long long> tmp;
  for (long long i = 1; i <= m; ++i)
    if (check[i]) tmp.push_back(i);
  sort(tmp.begin(), tmp.end(), cmp);
  for (long long i = tmp.size() - 1ll; i >= 0ll; --i) {
    long long id = tmp[i];
    if (!visit[edge[id].u]) dfs(edge[id].u, edge[id].cost);
    if (!visit[edge[id].v]) dfs(edge[id].v, edge[id].cost);
  }
  long long cnt = 0;
  for (long long i = 1; i <= m; ++i)
    if (!ans[i]) cnt++;
  cout << cnt;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= n; ++i) cin >> vertex[i], pr[i] = {i, vertex[i]};
  for (long long i = 1; i <= m; ++i) {
    long long u, v, cost;
    cin >> u >> v >> cost;
    edge[i] = {u, v, cost};
    eg[u].push_back({v, i});
  }
  findedge();
  return spread(), 0;
}
