#include <bits/stdc++.h>
using namespace std;
int n, m;
int x[100008];
int z[100008];
bool used[100008];
vector<pair<int, int> > g[100008];
vector<pair<int, pair<int, int> > > es;
int parent[100008];
int root(int x) {
  if (x == parent[x]) {
    return x;
  }
  return parent[x] = root(parent[x]);
}
bool unite(int x, int y) {
  int px = root(x), py = root(y);
  if (px == py) return false;
  if (px < py) {
    parent[py] = px;
    z[px] += z[py];
  } else {
    parent[px] = py;
    z[py] += z[px];
  }
  return true;
}
bool us[100008];
long long check(int s, unordered_set<int> u) {
  queue<int> que;
  for (auto v : u) us[v] = false;
  que.push(s);
  us[s] = true;
  long long res = z[s];
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    for (auto &p : g[v]) {
      int w = p.first;
      if (!used[p.second] || us[w]) continue;
      que.push(w);
      us[w] = true;
      res += z[w];
    }
  }
  return res;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> x[i];
  for (int i = 0; i < m; ++i) {
    int a, b, y;
    cin >> a >> b >> y;
    --a;
    --b;
    es.push_back(pair<int, pair<int, int> >(y, pair<int, int>(a, b)));
    used[i] = true;
  }
  sort((es).begin(), (es).end(), greater<pair<int, pair<int, int> > >());
  int sq = (int)(sqrt(m)) + 1;
  int c = (m + sq - 1) / sq;
  int ans = 0;
  for (int k = 0; k < sq; ++k) {
    for (int i = 0; i < n; ++i) {
      parent[i] = i;
      g[i].clear();
      z[i] = x[i];
    }
    for (int i = 0; i < m; ++i) {
      pair<int, pair<int, int> > &p = es[i];
      int a = p.second.first, b = p.second.second;
      if (i / sq != k && used[i]) unite(a, b);
    }
    unordered_set<int> u;
    for (int i = sq * k; i <= min(sq * (k + 1), m) - 1; ++i) {
      pair<int, pair<int, int> > &p = es[i];
      int a = p.second.first, b = p.second.second;
      int pa = root(a), pb = root(b);
      if (pa != pb) {
        g[pa].push_back(pair<int, int>(pb, i));
        u.insert(pa);
        g[pb].push_back(pair<int, int>(pa, i));
        u.insert(pb);
      } else {
        u.insert(pa);
      }
    }
    for (int i = c * k; i <= min(c * (k + 1), m) - 1; ++i) {
      pair<int, pair<int, int> > &p = es[i];
      int y = p.first, a = p.second.first, b = p.second.second;
      int pa = root(a), pb = root(b);
      long long r = check(pa, u);
      if (r < y) {
        used[i] = false;
        ++ans;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
