#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
struct UnionFind {
  vector<long long> data;
  vector<long long> horyu;
  vector<long long> sum;
  long long all = 0;
  UnionFind(vector<long long> &X) {
    long long size = X.size();
    sum = X;
    data.resize(size, -1);
    horyu.resize(size, 0);
  }
  bool unionSet(long long x, long long y, long long w) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
      sum[x] += sum[y];
    }
    horyu[x]++;
    if (w <= sum[x]) {
      all += horyu[x];
      horyu[x] = 0;
    }
    return x != y;
  }
  bool findSet(long long x, long long y) { return root(x) == root(y); }
  long long root(long long x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  long long size(long long x) { return -data[root(x)]; }
};
struct E {
  long long w;
  long long a;
  long long b;
  bool operator<(const E &right) const { return w < right.w; }
};
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N, M;
  cin >> N >> M;
  vector<long long> A(N);
  long long res = 0;
  for (long long i = 0; i < N; i++) {
    cin >> A[i];
  }
  UnionFind uf(A);
  vector<E> es;
  long long a, b, w;
  for (long long i = 0; i < M; i++) {
    cin >> a >> b >> w;
    a--;
    b--;
    es.push_back(E{w, a, b});
  }
  sort(es.begin(), es.end());
  for (long long i = 0; i < M; i++) {
    uf.unionSet(es[i].a, es[i].b, es[i].w);
  }
  cout << M - uf.all << endl;
}
