#include <bits/stdc++.h>
double pi = 3.141592653589793;
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
long long par[100005];
long long lank[100005];
void init(long long n) {
  for (long long i = 0; i < n; i++) {
    par[i] = i;
    lank[i] = 0;
  }
}
long long find(long long x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}
void unite(long long x, long long y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  if (lank[x] < lank[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (lank[x] == lank[y]) lank[x]++;
  }
}
bool same(long long x, long long y) { return find(x) == find(y); }
long long num[114514];
long long wei[114514];
signed main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < n; i++) num[i] = 0;
  long long x[114514];
  for (long long i = 0; i < n; i++) {
    cin >> x[i];
    wei[i] = x[i];
  }
  vector<vector<long long>> v;
  for (long long i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    v.push_back({c, a - 1, b - 1});
  }
  init(n);
  sort(v.begin(), v.end());
  long long ans = 0;
  for (long long i = 0; i < m; i++) {
    long long k = find(v[i][1]);
    long long w1 = wei[k], w2 = wei[find(v[i][2])];
    long long n1 = num[k], n2 = num[find(v[i][2])];
    long long cur = k;
    if (!same(v[i][1], v[i][2])) {
      unite(v[i][1], v[i][2]);
      cur = find(v[i][1]);
      wei[cur] = w1 + w2;
      num[cur] = n1 + n2 + 1;
    } else {
      num[k]++;
    }
    if (v[i][0] > wei[cur])
      continue;
    else {
      ans = max(ans, num[cur]);
    }
  }
  cout << m - ans << endl;
  return 0;
}
