#include <bits/stdc++.h>
using namespace std;
FILE* in = stdin;
FILE* out = stdout;
const int MAX = 100001;
struct Edge {
  int id, node1, node2, value;
  bool operator<(const Edge& r) const {
    return value != r.value ? value < r.value : id < r.id;
  }
};
int n, m;
int a[MAX];
Edge edges[MAX];
int maxx[MAX];
int parent[MAX];
int lastGood[MAX];
long long sum[MAX];
bool used[MAX];
vector<Edge> v[MAX];
int dyn[MAX];
int getLastGood(int node) {
  if (dyn[node] != -1) return dyn[node];
  int ret = lastGood[node];
  if (parent[node] != node) ret = max(ret, getLastGood(parent[node]));
  return dyn[node] = ret;
}
int recurse(int node, int limit) {
  int ret = 0;
  used[node] = true;
  for (int i = 0; i < (int)v[node].size(); i++) {
    if (v[node][i].value <= limit) {
      ret++;
      if (!used[v[node][i].node2]) {
        ret += recurse(v[node][i].node2, limit);
      }
    }
  }
  return ret;
}
int getComp(int node) {
  if (node == parent[node]) return node;
  return parent[node] = getComp(parent[node]);
}
int main(void) {
  fscanf(in, "%d %d", &n, &m);
  for (int i = 0; i < n; i++) fscanf(in, "%d", &a[i]);
  for (int i = 0; i < m; i++) {
    edges[i].id = i;
    fscanf(in, "%d %d %d", &edges[i].node1, &edges[i].node2, &edges[i].value);
    edges[i].node1--, edges[i].node2--;
    v[edges[i].node1].push_back(edges[i]);
    swap(edges[i].node1, edges[i].node2);
    v[edges[i].node2].push_back(edges[i]);
    swap(edges[i].node1, edges[i].node2);
  }
  sort(edges, edges + m);
  for (int node = 0; node < n; node++) {
    lastGood[node] = 0;
    sum[node] = a[node];
    maxx[node] = 0;
    parent[node] = node;
  }
  for (int e = 0; e < m; e++) {
    int comp1 = getComp(edges[e].node1);
    int comp2 = getComp(edges[e].node2);
    if (comp1 == comp2) {
      continue;
    }
    parent[comp2] = comp1;
    sum[comp1] += sum[comp2];
    maxx[comp1] = max(edges[e].value, max(maxx[comp1], maxx[comp2]));
    if (sum[comp1] >= maxx[comp1]) {
      lastGood[comp1] = edges[e].value;
    }
  }
  memset(dyn, -1, sizeof(dyn));
  int ans = 0;
  for (int node = 0; node < n; node++) {
    if (!used[node]) ans += recurse(node, getLastGood(node));
  }
  ans /= 2;
  fprintf(out, "%d\n", m - ans);
  return 0;
}
