#include <bits/stdc++.h>
using namespace std;
vector<bool> used;
vector<vector<pair<long long, long long> > > g;
vector<long long> dsu;
vector<long long> sum;
vector<long long> rang;
vector<bool> used1;
vector<long long> last;
vector<bool> used2;
long long pred(long long a) {
  if (a == dsu[a])
    return a;
  else
    return dsu[a] = pred(dsu[a]);
}
void unite(long long a, long long b) {
  a = pred(a);
  b = pred(b);
  if (a != b) {
    if (rang[a] < rang[b]) {
      swap(a, b);
    }
    dsu[b] = a;
    if (last[a] < last[b]) {
      if (last[a] != -1) {
        used[last[a]] = false;
      }
    } else if (last[a] > last[b]) {
      if (last[b] != -1) {
        used[last[b]] = false;
      }
    }
    last[a] = max(last[a], last[b]);
    sum[a] += sum[b];
    if (rang[a] == rang[b]) {
      rang[a]++;
    }
  }
}
void dfs(long long v) {
  used1[v] = true;
  for (long long i = 0; i < g[v].size(); i++) {
    long long to = g[v][i].first;
    long long ind = g[v][i].second;
    used2[ind] = true;
    if (!used1[to]) {
      dfs(to);
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m;
  cin >> n >> m;
  dsu.resize(n);
  rang.resize(n);
  last.resize(n, -1);
  used2.resize(m);
  sum.resize(n);
  for (long long i = 0; i < n; i++) {
    cin >> sum[i];
    rang[i] = 1;
    dsu[i] = i;
  }
  g.resize(n);
  used1.resize(n);
  used.resize(m);
  vector<pair<long long, pair<long long, long long> > > ver(m);
  for (long long i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    ver[i] = {c, {a, b}};
  }
  sort(ver.begin(), ver.end());
  for (long long i = 0; i < ver.size(); i++) {
    long long a = ver[i].second.first;
    long long b = ver[i].second.second;
    long long c = ver[i].first;
    unite(a, b);
    if (c <= sum[pred(a)]) {
      if (last[pred(a)] != -1) {
        used[last[pred(a)]] = false;
      }
      used[i] = true;
      last[pred(a)] = i;
    }
  }
  for (long long i = 0; i < ver.size(); i++) {
    long long a = ver[i].second.first;
    long long b = ver[i].second.second;
    g[a].push_back({b, i});
    g[b].push_back({a, i});
    if (used[i]) {
      dfs(a);
    }
  }
  long long ans = 0;
  for (long long i = 0; i < m; i++) {
    if (!used2[i]) {
      ans++;
    }
  }
  cout << ans;
  return 0;
}
