#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int read() {
  char c = getchar();
  int d = 0, f = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') f = -1;
  for (; c >= '0' && c <= '9'; d = d * 10 + c - 48, c = getchar())
    ;
  return d * f;
}
int n, m, w[N], fa[N];
struct edge {
  int x, y, id, s;
} e[N];
struct info {
  long long s1, s2, s3, S2, S3, s4;
} s[N * 2];
bool operator<(edge a, edge b) {
  return a.s < b.s || a.s == b.s && a.id < b.id;
}
int ask(int x) { return fa[x] == x ? x : fa[x] = ask(fa[x]); }
vector<int> E[N];
int ans = 0;
void dfs(int x) {
  if (s[x].s4) {
    ans += s[x].s4;
    return;
  }
  for (int i = 0; i <= ((int)E[x].size()) - 1; ++i) dfs(E[x][i]);
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; ++i) w[i] = read();
  for (int i = 1; i <= m; ++i) {
    int x = read(), y = read(), s = read();
    e[i].x = x;
    e[i].y = y;
    e[i].s = s;
    e[i].id = i;
  }
  sort(e + 1, e + m + 1);
  for (int i = 1; i <= n; ++i) s[i].s1 = w[i], s[i].s2 = 0, s[i].s3 = 0;
  for (int i = 1; i <= n * 2; ++i) fa[i] = i;
  int tot = n;
  for (int i = 1; i <= m; ++i) {
    int x = e[i].x, y = e[i].y;
    x = ask(x), y = ask(y);
    if (x == y) {
      s[x].S2 = e[i].s;
      s[x].S3++;
      if (s[x].s1 >= s[x].S2) s[x].s4++;
      continue;
    }
    ++tot;
    fa[x] = tot;
    fa[y] = tot;
    E[tot].push_back(x);
    E[tot].push_back(y);
    s[tot].s1 = s[x].s1 + s[y].s1;
    s[tot].S2 = s[tot].s2 = e[i].s;
    s[tot].S3 = s[tot].s3 = s[x].S3 + s[y].S3 + 1;
    if (s[tot].s1 >= s[tot].s2) s[tot].s4 = s[x].s3 + s[y].s3 + 1;
  }
  dfs(tot);
  cout << m - ans << endl;
}
