#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int N = 1e5 + 10;
int f[N], bad[N];
int64 sum[N];

struct Edge {
  int x, y, z;
  bool operator <(const Edge& rhs) const {
    return z < rhs.z;
  }
};

Edge e[N];

int find(int x) {
  if (f[x] != f[f[x]]) f[x] = find(f[x]);
  return f[x];
}

void join(int x, int y, int z) {
  int rx = find(x), ry = find(y);
  if (rx != ry) {
    f[ry] = rx;
    sum[rx] += sum[ry];
    bad[rx] += bad[ry];
  }
  if (z > sum[rx]) {
    ++bad[rx];
  } else {
    bad[rx] = 0;
  }
}

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%lld", &sum[i]);
    f[i] = i;
    bad[i] = 0;
  }
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d", &e[i].x, &e[i].y, &e[i].z);
    --e[i].x; --e[i].y;
  }
  sort(e, e + m);
  for (int i = 0; i < m; ++i) {
    join(e[i].x, e[i].y, e[i].z);
  }
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    if (find(i) == i) ret += bad[i];
  }
  printf("%d\n", ret);
  return 0;
}
