#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
long long POW(long long a, long long b, long long MMM = MOD) {
  long long ret = 1;
  for (; b; b >>= 1, a = (a * a) % MMM)
    if (b & 1) ret = (ret * a) % MMM;
  return ret;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) {
  if (a == 0 || b == 0) return a + b;
  return a * (b / gcd(a, b));
}
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
int ddx[] = {2, 2, -2, -2, 1, 1, -1, -1}, ddy[] = {1, -1, 1, -1, 2, -2, 2, -2};
struct info {
  int u, v;
  info(int a, int b) { u = a, v = b; }
};
int n, m;
tuple<int, int, int> e[100000];
int par[100001], num[100001];
long long w[100001];
stack<info> st;
vector<int> vv[100001];
int find(int u) {
  if (u == par[u]) return u;
  return find(par[u]);
}
void merge(int u, int v) {
  u = find(u), v = find(v);
  if (u == v) {
    st.push(info(-1, -1));
    return;
  }
  if (num[u] < num[v]) swap(u, v);
  st.push(info(u, v));
  par[v] = u;
  num[u] += num[v];
  w[u] += w[v];
  vv[u].push_back(v);
}
void rollback() {
  info I = st.top();
  st.pop();
  if (I.u < 0) return;
  par[I.u] = I.u;
  par[I.v] = I.v;
  num[I.u] -= num[I.v];
  w[I.u] -= w[I.v];
  vv[I.u].pop_back();
}
bool chk[100001];
void dfs(int x) {
  chk[x] = 1;
  for (int y : vv[x]) dfs(y);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int(i) = (1); (i) <= (n); (i) += (1)) par[i] = i, num[i] = 1;
  for (int(i) = (1); (i) <= (n); (i) += (1)) scanf("%lld", w + i);
  for (int(i) = (0); (i) <= (m - 1); (i) += (1)) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    e[i] = tuple<int, int, int>(z, x, y);
  }
  sort(e, e + m);
  for (int(i) = (0); (i) <= (m - 1); (i) += (1)) {
    int x, y;
    tie(ignore, x, y) = e[i];
    merge(x, y);
  }
  int ans = 0;
  for (int(i) = (m - 1); (i) >= (0); (i) -= (1)) {
    int z, x, y;
    tie(z, x, y) = e[i];
    if (!chk[x]) {
      if (w[x] >= z)
        dfs(x);
      else
        ans++;
    }
    rollback();
  }
  printf("%d", ans);
}
