#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];
class edge {
 public:
  int u;
  int v;
  int w;
};
vector<edge> e;
vector<int> par, rk, cn;
void initUnion(int n) {
  for (int i = 0; i < n; i++) {
    par.push_back(i);
    rk.push_back(1);
    cn.push_back(0);
  }
}
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];
  cn[ry] += cn[rx];
  par[rx] = ry;
}
bool same(int x, int y) {
  int rx = root(x);
  int ry = root(y);
  return rx == ry;
}
bool comp(edge v, edge u) { return v.w < u.w; }
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--;
    edge *ne = new edge;
    ne->u = u;
    ne->v = v;
    ne->w = w;
    e.push_back(*ne);
  }
  sort(e.begin(), e.end(), comp);
  int ans = m;
  for (int i = 0; i < m; i++) {
    initUnion(n);
    int w = e[i].w;
    int v = e[i].v;
    int u = e[i].u;
    if (!same(u, v)) {
      int Ru = root(u);
      int Rv = root(v);
      unite(u, v);
    }
    int Ru = root(u);
    cn[Ru]++;
    if (X[Ru] >= w) {
      ans -= cn[Ru];
      cn[Ru] = 0;
    }
  }
  cout << ans << endl;
  return 0;
}
