#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const long long MX = 1e5 + 10;
long long lead[MX], rang[MX], w[MX], n, m, res[MX], used[MX], ans = 0;
vector<pair<long long, long long> > g[MX];
pair<long long, pair<long long, long long> > edg[MX];
long long find(long long x) {
  if (lead[x] == x) return x;
  return lead[x] = find(lead[x]);
}
void unite(long long a, long long b) {
  long long x = find(a);
  long long y = find(b);
  if (x == y) return;
  if (rang[x] >= rang[y]) swap(x, y);
  lead[x] = y;
  if (rang[x] == rang[y]) rang[y]++;
  w[y] += w[x];
}
void dfs(long long v, long long val) {
  for (auto c : g[v]) {
    if (c.first <= val && used[c.first] == 0) {
      used[c.first] = 1;
      dfs(c.second, val);
      ans++;
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= n; ++i) {
    cin >> w[i];
    lead[i] = i;
  }
  for (long long i = 0; i < m; ++i) {
    long long j, x, y;
    cin >> x >> y >> j;
    edg[i] = {j, {x, y}};
  }
  sort(edg, edg + m);
  for (long long i = 0; i < m; ++i) {
    long long x = edg[i].second.first, y = edg[i].second.second;
    g[x].push_back({i, y});
    g[y].push_back({i, x});
  }
  for (long long i = 0; i < m; ++i) {
    unite(edg[i].second.first, edg[i].second.second);
    res[i] = (w[lead[edg[i].second.second]] >= edg[i].first);
  }
  for (long long i = m - 1; i >= 0; --i) {
    if (res[i] == 1) dfs(edg[i].second.first, i);
  }
  cout << m - ans << '\n';
  return 0;
}
