#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
int n, m;
int X[100005];
vector<pair<int, pair<int, int>>> e;
vector<int> par, rk;
void initUnion(int n) {
  for (int i = 0; i < n; i++) {
    par.push_back(i);
    rk.push_back(1);
  }
}
int root(int x) {
  if (par[x] == x) return x;
  return par[x] = root(par[x]);
}
void unite(int x, int y) {
  int rx = root(x);
  int ry = root(y);
  if (rx == ry) return;
  if (rk[ry] < rk[rx]) swap(rx, ry);
  X[ry] += X[rx];
  rk[ry] += rk[rx];
  par[rx] = ry;
}
bool same(int x, int y) {
  int rx = root(x);
  int ry = root(y);
  return rx == ry;
}
bool comp(pair<int, pair<int, int>> v, pair<int, pair<int, int>> u) {
  return v.first < u.first;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> X[i];
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    e.push_back(make_pair(w, make_pair(u, v)));
  }
  sort(e.begin(), e.end());
  int ans = n;
  for (int i = 0; i < m; i++) {
    initUnion(n);
    int w = e.front().first;
    int v = e.front().second.first;
    int u = e.front().second.second;
    if (!same(u, v)) {
      int Ru = root(u);
      int Rv = root(v);
      unite(u, v);
    }
    int Ru = root(u);
    if (X[Ru] >= w) {
      ans--;
    }
  }
  cout << ans << endl;
  return 0;
}
