#include <bits/stdc++.h>
using namespace std;
vector<long long> X;
struct UnionFind {
  vector<int> par;
  vector<int> sizes;
  vector<long long> Xsum;
  vector<long long> Ymax;
  UnionFind(int n) : par(n), sizes(n, 1), Xsum(n), Ymax(n) {
    for (int i = 0; i < n; i++) par[i] = i;
    for (int i = 0; i < n; i++) Xsum[i] = X[i];
  }
  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);
  }
  void unite(int x, int y, long long w) {
    x = find(x);
    y = find(y);
    if (sizes[x] < sizes[y]) swap(x, y);
    if (x == y) {
      Ymax[x] = max(Ymax[x], w);
      return;
    }
    par[y] = x;
    sizes[x] += sizes[y];
    Xsum[x] += Xsum[y];
    Ymax[x] = max({Ymax[x], Ymax[y], w});
  }
  bool pre_unite(int x, int y, long long w) {
    x = find(x);
    y = find(y);
    if (sizes[x] < sizes[y]) swap(x, y);
    if (x == y) {
      if (Xsum[x] < max(Ymax[x], w))
        return false;
      else
        return true;
    }
    if (Xsum[x] + Xsum[y] < max({Ymax[x], Ymax[y], w}))
      return false;
    else
      return true;
  }
  bool is_ok(int x, int y) {
    x = find(x);
    y = find(y);
    if (sizes[x] < sizes[y]) swap(x, y);
    if (Xsum[x] < Ymax[x])
      return false;
    else
      return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return sizes[find(x)]; }
};
int main() {
  int N, M;
  cin >> N >> M;
  X.resize(N);
  for (int i = 0; i < N; i++) cin >> X[i];
  vector<pair<long long, pair<int, int>>> E;
  for (int i = 0; i < M; i++) {
    int a, b;
    long long y;
    cin >> a >> b >> y;
    a--;
    b--;
    E.push_back(make_pair(y, make_pair(a, b)));
  }
  sort(E.begin(), E.end());
  vector<pair<int, int>> dame;
  UnionFind uf(N);
  int ans = 0;
  for (int i = 0; i < E.size(); i++) {
    int a, b;
    a = E[i].second.first;
    b = E[i].second.second;
    uf.unite(a, b, E[i].first);
    for (int j2 = 0; j2 < dame.size(); j2++) {
      int j = j2;
      int a, b;
      a = dame[j].first;
      b = dame[j].second;
      if (uf.is_ok(a, b)) {
        swap(dame[j], dame.back());
        dame.pop_back();
        j2--;
        ans++;
      }
    }
    if (uf.is_ok(a, b)) {
      ans++;
    } else
      dame.push_back(make_pair(a, b));
  }
  cout << M - ans << endl;
  return 0;
}
