#include <bits/stdc++.h>
using namespace std;
bool LTE(double a, double b) { return (fabs((a) - (b)) < (1e-8)) || a < b; }
bool LT(double a, double b) { return !(fabs((a) - (b)) < (1e-8)) && a < b; }
struct Edge {
  int s, t;
  long long w;
  bool operator<(const Edge &e) const {
    if (w != e.w) return w < e.w;
    if (s != e.s) return s < e.s;
    return t < e.t;
  }
};
long long need[100010], sum[100010], ans[100010];
int par[100010];
int find(int x) {
  if (x == par[x]) return x;
  return par[x] = find(par[x]);
}
void unite(int x, int y) {
  x = find(x), y = find(y);
  if (x != y) par[x] = y;
}
const bool debug = 0;
int V, E;
long long X[100010];
void compute() {}
int main() {
  cin >> V >> E;
  for (int i = 0; i < V; ++i) par[i] = i;
  for (int i = 0; i < V; ++i) cin >> X[i];
  vector<Edge> es;
  for (int i = 0; i < E; ++i) {
    int s, t, w;
    cin >> s >> t >> w;
    --s, --t;
    es.push_back((Edge){s, t, w});
  }
  sort(es.begin(), es.end());
  for (int i = 0; i < V; ++i) need[i] = 0, ans[i] = 0;
  for (int i = 0; i < V; ++i) sum[i] = X[i];
  map<int, int> es_size;
  for (int i = 0; i < (int)es.size(); ++i) {
    int s = es[i].s, t = es[i].t;
    long long w = es[i].w;
    if (debug) {
      cout << "[" << i << "] " << s << "," << t << " w = " << w << endl;
      cout << "  find(" << s << ") = " << find(s) << endl;
      cout << "  find(" << t << ") = " << find(t) << endl;
    }
    if (find(s) != find(t)) {
      long long tmp = sum[find(s)] + sum[find(t)];
      long long maxi = max(max(need[find(s)], need[find(t)]), w);
      long long new_size = es_size[find(s)] + es_size[find(t)] + 1;
      long long ans_maxi = ans[find(s)] + ans[find(t)];
      if (debug) {
        cout << "  sum of vertex weight = " << tmp << endl;
        cout << "  max edge weight = " << maxi << endl;
        cout << "  edge num = " << new_size << endl;
        cout << "  ans maxi = " << ans_maxi << endl;
      }
      unite(s, t);
      es_size[find(s)] = new_size;
      sum[find(s)] = tmp;
      need[find(s)] = max(need[find(s)], maxi);
      need[find(s)] = max(need[find(s)], w);
      ans[find(s)] = max(ans[find(s)], ans_maxi);
    } else {
      need[find(s)] = max(need[find(s)], w);
      if (need[find(s)] <= sum[find(s)]) {
        ++ans[find(s)];
      }
    }
    if (need[find(s)] <= sum[find(s)]) {
      if (debug) {
        cout << "  ok! " << need[find(s)] << " <= " << sum[find(s)] << endl;
        cout << "  ans[" << i << "] (" << ans[i] << ") ?= " << es_size[find(s)]
             << endl;
      }
      ans[find(s)] = max(ans[find(s)], (long long)es_size[find(s)]);
    }
  }
  set<int> gs;
  for (int i = 0; i < V; ++i) gs.insert(find(i));
  long long maxi = 0;
  if (debug) {
    for (int i = 0; i < V; ++i) {
      cout << i << " : " << ans[i] << endl;
    }
  }
  for (auto v : gs) {
    if (debug) {
      cout << "  ?? v = " << v << endl;
    }
    maxi += ans[v];
  }
  if (debug) {
    cout << "FINALLY! " << maxi << endl;
  }
  cout << E - maxi << endl;
  compute();
  return 0;
}
