#include <bits/stdc++.h>
using namespace std;
template <typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) {
  os << pai.first << ' ' << pai.second;
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
  for (int i = 0, _i = (((int)(v).size())); i < _i; i++) cout << v[i] << ' ';
  return os;
}
template <typename T, typename V>
istream &operator>>(istream &is, pair<T, V> &pai) {
  is >> pai.first >> pai.second;
  return is;
}
int N, M;
int par[100001];
int edges[100001];
int maxv[100001];
int sumv[100001];
pair<int, pair<int, int> > edge[100001];
int find(int x) { return x == par[x] ? x : par[x] = find(par[x]); }
int main(void) {
  iostream::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  cin >> N >> M;
  for (int i = 1, _i = (N); i <= _i; i++) {
    int t;
    cin >> t;
    sumv[i] = t;
    par[i] = i;
  }
  for (int i = 0, _i = (M); i < _i; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    edge[i] = make_pair(c, make_pair(a, b));
  }
  sort(edge, edge + M);
  int res = 0;
  for (int i = 0, _i = (M); i < _i; i++) {
    int g1 = find(edge[i].second.first);
    int g2 = find(edge[i].second.second);
    int we = edge[i].first;
    if (g1 == g2) {
      if (sumv[g1] >= we)
        res++;
      else
        edges[g1]++;
    } else {
      par[g2] = g1;
      maxv[g1] = we;
      edges[g1] += edges[g2] + 1;
      sumv[g1] += sumv[g2];
      if (sumv[g1] >= maxv[g1]) {
        res += edges[g1];
        edges[g1] = 0;
      }
    }
  }
  cout << M - res;
}
