#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:108777216")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
using namespace std;
int const MAX_N = 100 * 1002;
int cost[MAX_N];
set<pair<int, pair<int, int> > > e[MAX_N];
struct pp {
  int a, b, cost;
} e_list[MAX_N];
bool operator<(const pp &a, const pp &b) { return a.cost < b.cost; }
vector<set<pair<int, int> > > rem_e;
vector<set<int> > comps;
int comp_id[MAX_N];
long long comp_sum[MAX_N];
int nnew[MAX_N];
int DFS_FLAG = 0;
void dfs(int v, set<int> &cmp, long long &sum_V) {
  sum_V += cost[v];
  cmp.insert(v);
  nnew[v] = DFS_FLAG;
  for (set<pair<int, pair<int, int> > >::iterator iter = e[v].begin();
       iter != e[v].end(); ++iter) {
    int new_v = iter->second.first;
    if (nnew[new_v] != DFS_FLAG) dfs(new_v, cmp, sum_V);
  }
}
void delete_back_edge(int c_index) {
  set<pair<int, int> >::iterator iter = rem_e[c_index].end();
  iter--;
  int edge_cost = iter->first;
  int edge_index = iter->second;
  rem_e[c_index].erase(iter);
  int a = e_list[edge_index].a;
  int b = e_list[edge_index].b;
  e[a].erase(make_pair(edge_index, make_pair(b, e_list[edge_index].cost)));
  e[b].erase(make_pair(edge_index, make_pair(a, e_list[edge_index].cost)));
  DFS_FLAG++;
  set<int> cmp;
  long long sum_V = 0;
  dfs(a, cmp, sum_V);
  if (cmp.size() != comps[c_index].size()) {
    set<pair<int, int> > e1, e2;
    for (set<pair<int, int> >::iterator iter = rem_e[c_index].begin();
         iter != rem_e[c_index].end(); ++iter) {
      int edge_cost = iter->first;
      int edge_index = iter->second;
      int a = e_list[edge_index].a;
      int b = e_list[edge_index].b;
      if (cmp.find(a) != cmp.end()) {
        e2.insert(*iter);
      } else
        e1.insert(*iter);
    }
    set<int> v1;
    for (set<int>::iterator iter = comps[c_index].begin();
         iter != comps[c_index].end(); ++iter)
      if (cmp.find(*iter) == cmp.end()) v1.insert(*iter);
    comps.push_back(cmp);
    rem_e.push_back(e2);
    comps[c_index] = v1;
    rem_e[c_index] = e1;
    comp_sum[comps.size() - 1] = sum_V;
    comp_sum[c_index] -= sum_V;
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", &cost[i]);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    a--;
    b--;
    e_list[i].a = a;
    e_list[i].b = b;
    e_list[i].cost = c;
    e[a].insert(make_pair(i, make_pair(b, c)));
    e[b].insert(make_pair(i, make_pair(a, c)));
  }
  int ans = 0;
  for (int i = 0; i < n; i++) comp_sum[0] += cost[i];
  for (int i = 0; i < m; i++) comp_id[i] = 0;
  comps.clear();
  set<int> cur;
  for (int i = 0; i < n; i++) cur.insert(i);
  comps.push_back(cur);
  rem_e.resize(1);
  for (int i = 0; i < m; i++) rem_e[0].insert(make_pair(e_list[i].cost, i));
  while (!rem_e.empty()) {
    int fnd = 0;
    int old_size = (int)comps.size();
    for (int j = 0; j < old_size; j++)
      if (rem_e[j].size() > 0) {
        set<pair<int, int> >::iterator iter = rem_e[j].end();
        iter--;
        if (iter->first > comp_sum[j]) {
          fnd = 1;
          delete_back_edge(j);
          ans++;
        }
      }
    if (!fnd) break;
  }
  cout << ans;
  return 0;
}
