#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 6;
struct node {
  int par;
  long long sum, mx;
} dsu[N];
int qan, x[N];
void make_node(int i, int k) {
  dsu[i].par = i;
  dsu[i].mx = 0;
  dsu[i].sum = k;
}
int get(int p) {
  if (dsu[p].par == p) return p;
  return dsu[p].par = get(dsu[p].par);
}
void unite(int a, int b, long long len) {
  a = get(a);
  b = get(b);
  if (a != b) {
    if (dsu[a].sum < dsu[a].mx) qan--;
    if (dsu[b].sum < dsu[b].mx) qan--;
    dsu[a].sum += dsu[b].sum;
    dsu[a].mx = max(len, max(dsu[a].mx, dsu[b].mx));
    dsu[b].par = a;
  } else {
    dsu[a].mx = max(dsu[a].mx, len);
  }
  if (dsu[a].sum < dsu[a].mx) qan++;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < (n); ++i) {
    cin >> x[i];
    make_node(i + 1, x[i]);
  }
  vector<pair<int, pair<int, int> > > v;
  for (int i = 0; i < (m); ++i) {
    int l, a, b;
    cin >> a >> b >> l;
    v.push_back({l, {a, b}});
  }
  sort(v.begin(), v.end());
  int ans = 0;
  for (int i = 0; i < (m); ++i) {
    unite(v[i].second.first, v[i].second.second, v[i].first);
    if (qan == 0) ans = i + 1;
  }
  cout << m - ans << endl;
  return 0;
}
