#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int N = 1E5 + 100;
struct E {
  int to, cost;
};
vector<E> edges;
set<int> G[N];
int ans = 0;
void addedge(int u, int v, int w) {
  edges.push_back({v, w});
  edges.push_back({u, w});
  int m = (int)edges.size();
  G[u].insert(m - 2);
  G[v].insert(m - 1);
}
void deledge(int u, int id) {
  int v = edges[id].to;
  G[u].erase(id);
  G[v].erase(id ^ 1);
  ans++;
}
int n, x[N], vis[N];
void dfs(const vector<int>& ids) {
  if (ids.size() <= 1) return;
  LL sum = 0;
  for (int u : ids) sum += x[u];
  ;
  vector<vector<int>> comps;
  for (int s : ids) {
    if (vis[s]) continue;
    comps.emplace_back();
    queue<int> q;
    q.push(s);
    vis[s] = 1;
    comps.back().push_back(s);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (auto it = G[u].begin(); it != G[u].end();) {
        const E& e = edges[*it];
        if (e.cost > sum) {
          deledge(u, *it++);
        } else {
          if (!vis[e.to]) {
            q.push(e.to);
            vis[e.to] = 1;
            comps.back().push_back(e.to);
          }
          it++;
        }
      }
    }
  }
  for (int s : ids) vis[s] = 0;
  if (comps.size() == 1) return;
  for (const auto& comp : comps) {
    dfs(comp);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (decay<decltype(n + 1)>::type i = (1), _i = (n + 1); i < _i; ++i)
    scanf("%d", &x[i]);
  for (decay<decltype(m)>::type i = (0), _i = (m); i < _i; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    addedge(u, v, w);
  }
  vector<int> tests;
  for (decay<decltype(n + 1)>::type i = (1), _i = (n + 1); i < _i; ++i)
    tests.push_back(i);
  dfs(tests);
  cout << ans << endl;
}
