#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
T div_floor(T a, T b) {
  if (b < 0) a *= -1, b *= -1;
  return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
  if (b < 0) a *= -1, b *= -1;
  return a > 0 ? (a - 1) / b + 1 : a / b;
}
constexpr long long mod = 1e9 + 7;
constexpr long long INF = mod * mod;
constexpr int MAX = 100010;
typedef struct UnionFindTree {
  vector<int> par;
  vector<long long> sum;
  UnionFindTree(int n) {
    par.resize(n, -1);
    sum.resize(n, 0);
  }
  bool is_root(int x) { return par[x] < 0; }
  int find(int x) {
    if (is_root(x)) return x;
    return par[x] = find(par[x]);
  }
  int size(int x) { return -par[find(x)]; }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (size(x) < size(y)) swap(x, y);
    par[x] += par[y];
    par[y] = x;
    sum[x] += sum[y];
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
} UF;
int n, m, a[MAX], b[MAX];
bool used[MAX];
vector<int> G[MAX], edge;
vector<long long> x(MAX), y(MAX);
int ans = 0;
void dfs(int v, long long tmp) {
  for (auto e : G[v])
    if (!used[e] && y[e] <= tmp) {
      used[e] = true;
      ++ans;
      dfs(b[e], tmp);
    }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int((i)) = (int)(0); ((i)) < (int)((n)); ++((i))) scanf("%lld", &x[i]);
  for (int((i)) = (int)(0); ((i)) < (int)((m)); ++((i))) {
    scanf("%d%d%lld", &a[i], &b[i], &y[i]);
    --a[i];
    --b[i];
    G[a[i]].push_back(i);
    G[b[i]].push_back(i);
  }
  vector<int> E(m);
  for (int((i)) = (int)(0); ((i)) < (int)((m)); ++((i))) E[i] = i;
  sort(E.begin(), E.end(),
       [&](const int &i, const int &j) { return y[i] < y[j]; });
  UF uf(n);
  for (int((i)) = (int)(0); ((i)) < (int)((n)); ++((i))) uf.sum[i] = x[i];
  for (auto e : E) {
    uf.unite(a[e], b[e]);
    if (uf.sum[uf.find(a[e])] >= y[e]) {
      edge.push_back(e);
    }
  }
  reverse(edge.begin(), edge.end());
  memset(used, false, sizeof(used));
  for (auto e : edge)
    if (!used[e]) {
      dfs(a[e], y[e]);
    }
  printf("%d\n", m - ans);
}
