#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<pair<int, long long> > G[100005];
vector<long long> V;
vector<pair<long long, pair<int, int> > > E;
class union_find {
  int n;
  vector<int> par;
  vector<int> rank;

 public:
  union_find(int n) {
    this->n = n;
    par = vector<int>(n, 0);
    for (int i = 0; i < (n); i++) {
      par[i] = i;
    }
    rank = vector<int>(n, 0);
  }
  int find(int x) {
    if (par[x] == x) {
      return x;
    } else {
      par[x] = find(par[x]);
      return par[x];
    }
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) {
      return;
    }
    if (rank[x] < rank[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
};
int main() {
  cin >> N >> M;
  union_find uf(N);
  vector<long long> vsum, vcsum, emax;
  V.resize(N);
  vsum.resize(N, 0), vcsum.resize(N, 1), emax.resize(N, 0);
  E.resize(M);
  for (int i = 0; i < (N); i++) {
    cin >> vsum[i];
  }
  for (int i = 0; i < (M); i++) {
    int a, b;
    long long y;
    cin >> a >> b >> y;
    G[a].push_back(make_pair(b, y));
    G[b].push_back(make_pair(a, y));
    E[i] = make_pair(y, make_pair(a, b));
  }
  sort(E.begin(), E.end());
  int ans = 0;
  int ok = N;
  int count = 0;
  for (auto e : E) {
    count++;
    long long cost = e.first;
    int v1 = e.second.first, v2 = e.second.second;
    v1 = uf.find(v1), v2 = uf.find(v2);
    if (vsum[v1] >= emax[v1]) {
      ok -= vcsum[v1];
    }
    if (vsum[v2] >= emax[v2]) {
      ok -= vcsum[v2];
    }
    uf.unite(v1, v2);
    int par = uf.find(v1);
    vsum[par] = vsum[v1] + vsum[v2];
    emax[par] = max(max(emax[v1], emax[v2]), cost);
    vcsum[par] = vcsum[v1] + vcsum[v2];
    if (vsum[par] >= emax[par]) {
      ok += vcsum[par];
    }
    if (ok == N) {
      ans = count;
    }
  }
  cout << N - ans << endl;
}
