#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e15;
const long long int MOD = 1e9 + 7;
template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()) {
  return vector2<T>(n0, vector<T>(n1, e));
}
template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()) {
  return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}
template <typename T>
class UnionFind {
 public:
  long long int n;
  vector<T> p, rank;
  UnionFind(long long int n) : n(n), p(n + 1, -1), rank(n + 1) {}
  long long int find(long long int v) {
    if (p[v] == -1) {
      return v;
    }
    p[v] = find(p[v]);
    return p[v];
  }
  bool unite(long long int u, long long int v) {
    u = find(u);
    v = find(v);
    if (u == v) {
      return false;
    }
    if (rank[u] < rank[v]) {
      swap(u, v);
    }
    if (rank[u] == rank[v]) {
      rank[u]++;
    }
    p[v] = u;
    return true;
  }
};
struct edge {
  long long int w, x, y;
};
bool compare(edge a, edge b) { return a.w < b.w; }
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int n, m;
  cin >> n >> m;
  vector<long long int> x(n + 1);
  for (long long int i = 0; i < (n); ++i) {
    cin >> x[i + 1];
  }
  auto graph = initVec2<pair<long long int, long long int>>(n + 1, 0);
  vector<edge> ve(m);
  for (long long int i = 0; i < (m); ++i) {
    long long int a, b, y;
    cin >> a >> b >> y;
    ve[i] = {y, a, b};
    graph[a].emplace_back(b, y);
    graph[b].emplace_back(a, y);
  }
  sort((ve).begin(), (ve).end(), compare);
  UnionFind<long long int> uf(n + 1);
  vector<long long int> sum(n + 1);
  for (long long int i = 0; i < (n + 1); ++i) {
    sum[i] = x[i];
  }
  stack<edge> st;
  for (long long int i = 0; i < (m); ++i) {
    long long int rx = uf.find(ve[i].x);
    long long int ry = uf.find(ve[i].y);
    long long int s = sum[rx] + sum[ry];
    if (uf.unite(ve[i].x, ve[i].y)) {
      sum[uf.find(rx)] = s;
      if (s >= ve[i].w) {
        st.push(ve[i]);
      }
    }
  }
  vector<bool> used(n + 1, false);
  long long int ans = 0;
  while (not st.empty()) {
    edge e = st.top();
    st.pop();
    if (used[e.x]) {
      continue;
    }
    used[e.x] = true;
    stack<long long int> next;
    next.push(e.x);
    while (not next.empty()) {
      long long int v = next.top();
      next.pop();
      for (pair<long long int, long long int> p : graph[v]) {
        long long int u = p.first;
        long long int w = p.second;
        if (w <= e.w && not used[u]) {
          ans++;
          used[u] = true;
          next.push(u);
        }
      }
    }
  }
  cout << m - ans << endl;
  return 0;
}
