#include <bits/stdc++.h>
using namespace std;
template <class T, class T2>
inline int chkmax(T &x, const T2 &y) {
  return x < y ? x = y, 1 : 0;
}
template <class T, class T2>
inline int chkmin(T &x, const T2 &y) {
  return x > y ? x = y, 1 : 0;
}
const int MAXN = (1 << 20);
struct dsu {
  int sz;
  vector<int> par, psz;
  void init(int n) {
    sz = n;
    par.assign(sz + 1, 0);
    psz.assign(sz + 1, 0);
    for (int i = 0; i <= sz; i++) par[i] = i, psz[i] = 1;
  }
  int root(int u) { return par[u] = ((u == par[u]) ? u : root(par[u])); }
  bool connected(int x, int y) { return root(x) == root(y); }
  void unite(int x, int y) {
    x = root(x), y = root(y);
    if (x == y) return;
    if (psz[x] > psz[y]) swap(x, y);
    par[x] = y, psz[y] += psz[x];
  }
} DS;
int n, m, w[MAXN];
vector<pair<int, pair<int, int> > > ed;
void read() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> w[i];
  for (int i = 0; i < m; i++) {
    int u, v, x;
    cin >> u >> v >> x;
    ed.push_back({x, {u, v}});
  }
}
bool in_tr[MAXN];
vector<pair<int, int> > adj[MAXN];
int64_t sum[MAXN];
int comp[MAXN];
bool vis[MAXN];
void dfs(int u, int C) {
  vis[u] = 1;
  comp[u] = C;
  for (auto v : adj[u])
    if (!vis[v.first]) dfs(v.first, C);
}
int psz = 0;
set<pair<int64_t, int> > ST;
void update_edge(int i, int64_t old) {
  ST.erase({old - ed[i].first, i});
  ST.insert({sum[comp[ed[i].second.second]] - ed[i].first, i});
}
void assign(int u, int pr, int nC, int C) {
  comp[u] = nC;
  sum[nC] += w[u];
  for (auto e : adj[u])
    if (comp[e.first] == C && e.first != pr) assign(e.first, u, nC, C);
}
void update(int u, int pr, int C, int64_t OLD) {
  for (auto e : adj[u])
    if (e.first != pr && comp[e.first] == C) {
      update_edge(e.second, OLD);
      update(e.first, u, C, OLD);
    }
}
void solve() {
  sort(ed.begin(), ed.end());
  DS.init(n);
  for (int i = 0; i < m; i++) {
    int u = ed[i].second.first, v = ed[i].second.second;
    if (!DS.connected(u, v)) {
      in_tr[i] = 1;
      adj[u].push_back({v, i});
      adj[v].push_back({u, i});
      DS.unite(u, v);
    }
  }
  psz++;
  for (int i = 1; i <= n; i++)
    if (!vis[i]) dfs(i, psz++);
  for (int i = 1; i <= n; i++) sum[comp[i]] += w[i];
  int answer = 0;
  for (int i = 0; i < m; i++)
    if (in_tr[i]) {
      int64_t diff = sum[comp[ed[i].second.first]] - ed[i].first;
      ST.insert({diff, i});
    }
  while (true) {
    if (ST.empty()) break;
    auto it = ST.begin();
    if (it->first >= 0) break;
    int i = it->second;
    int u = ed[i].second.first, v = ed[i].second.second;
    ST.erase(it);
    answer++;
    int64_t old = sum[comp[u]];
    assign(u, v, psz++, comp[u]);
    sum[comp[v]] -= sum[comp[u]];
    update(u, v, comp[u], old);
    update(v, u, comp[v], old);
  }
  for (int i = 0; i < m; i++)
    if (!in_tr[i]) {
      int u = ed[i].second.first, v = ed[i].second.second, w = ed[i].first;
      if (comp[u] != comp[v])
        answer++;
      else if (w > sum[comp[u]])
        answer++;
    }
  cout << answer << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  read();
  solve();
  return 0;
}
