#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long inf = 1ll << 61;
const long long logN = 18;
long long par[100006], siz[100006];
long long mxe[100006], sumv[100006];
long long x[100006];
pair<long long, pair<long long, long long> > e[100006];
void init(long long n) {
  for (long long i = 0; i < n; i++) {
    par[i] = i;
    siz[i] = 1;
    sumv[i] = x[i];
  }
}
long long find(long long x) {
  if (par[x] == x) return x;
  return par[x] = find(par[x]);
}
void unite(long long x, long long y, long long v) {
  x = find(x), y = find(y);
  mxe[x] = max(mxe[x], v);
  if (x == y) return;
  if (siz[x] < siz[y]) swap(x, y);
  par[y] = x;
  siz[x] += siz[y];
  sumv[x] += sumv[y];
  mxe[x] = max(mxe[x], mxe[y]);
}
signed main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < n; i++) cin >> x[i];
  init(n);
  for (long long i = 0; i < m; i++) {
    long long a, b, y;
    cin >> a >> b >> y;
    a--;
    b--;
    e[i] = pair<long long, pair<long long, long long> >(
        y, pair<long long, long long>(a, b));
  }
  sort(e, e + m);
  long long ans = 0;
  for (long long i = 0; i < m; i++) {
    long long X = e[i].second.first, y = e[i].second.second;
    unite(X, y, e[i].first);
    if (sumv[find(X)] >= mxe[find(X)]) ans = i + 1;
  }
  cout << m - ans << endl;
}
