#include <bits/stdc++.h>
constexpr int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct UnionFind {
  std::vector<int> par;
  std::vector<int> sizes;
  void init(int n) {
    par.resize(n);
    sizes.resize(n);
    for (int i = 0; i < n; ++i) {
      par[i] = i;
      sizes[i] = 1;
    }
  }
  int root(int a) { return par[a] == a ? a : par[a] = root(par[a]); }
  bool same(int x, int y) { return root(x) == root(y); }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (sizes[x] < sizes[y]) std::swap(x, y);
    par[y] = x;
    sizes[x] += sizes[y];
  }
  int size(int x) { return sizes[root(x)]; }
};
struct Edge {
  ll from, to, cost;
};
bool comp(Edge &a, Edge &b) { return a.cost < b.cost; }
vi v;
UnionFind uf;
int solve(vector<int> &vs, vector<Edge> &es) {
  ll sum = 0;
  for (ll i = 0; i < ll(vs.size()); ++i) sum += v[vs[i]];
  ll m = 0;
  for (ll i = 0; i < ll(es.size()); ++i) chmax(m, es[i].cost);
  if (sum >= m) return 0;
  int ret = 0;
  while (!es.empty() && es.back().cost > sum) {
    es.pop_back();
    ret++;
  }
  for (ll i = 0; i < ll(vs.size()); ++i) {
    uf.par[vs[i]] = vs[i];
    uf.sizes[vs[i]] = 1;
  }
  for (ll i = 0; i < ll(es.size()); ++i) {
    uf.unite(es[i].from, es[i].to);
  }
  set<int> st;
  for (ll i = 0; i < ll(vs.size()); ++i) st.insert(uf.root(vs[i]));
  map<int, vector<int>> mpv;
  map<int, vector<Edge>> mpe;
  for (ll i = 0; i < ll(vs.size()); ++i) {
    mpv[uf.root(vs[i])].push_back(vs[i]);
  }
  for (ll i = 0; i < ll(es.size()); ++i) {
    mpe[uf.root(es[i].from)].push_back(es[i]);
  }
  for (auto a : st) {
    ret += solve(mpv[a], mpe[a]);
  }
  return ret;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  v.resize(n);
  for (ll i = 0; i < ll(n); ++i) cin >> v[i];
  vector<Edge> e(m);
  uf.init(n);
  for (ll i = 0; i < ll(m); ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    e[i] = Edge{a, b, c};
  }
  sort((e).begin(), (e).end(), comp);
  vi vs;
  for (ll i = 0; i < ll(n); ++i) vs.push_back(i);
  cout << solve(vs, e) << endl;
}
