#include <bits/stdc++.h>
using namespace std;
inline long long min(long long x, long long y) { return x < y ? x : y; }
inline long long max(long long x, long long y) { return x > y ? x : y; }
const int Maxn = 1e5 + 5;
int n, m, f[Maxn], num[Maxn], sum[Maxn], ans;
struct str {
  int a, b, val;
  bool operator<(str an) const { return val < an.val; }
} e[Maxn];
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
int main() {
  int u, v;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &sum[i]);
    f[i] = i;
  }
  for (int i = 1; i <= m; i++) scanf("%d%d%d", &e[i].a, &e[i].b, &e[i].val);
  sort(e + 1, e + m + 1);
  for (int i = 1; i <= m; i++) {
    u = find(e[i].a);
    v = find(e[i].b);
    if (u != v) {
      num[u] += num[v];
      sum[u] += sum[v];
      f[v] = u;
    }
    num[u]++;
    if (sum[u] >= e[i].val) {
      ans += num[u];
      num[u] = 0;
    }
  }
  cout << m - ans << endl;
  return 0;
}
