#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
struct Tll {
  LL first, second, third;
};
struct Fll {
  LL first, second, third, fourth;
};
LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum, ans, d[700000], a[200000],
    b[200000];
string str, ss;
bool f[4000][4000];
char c[4000][4000];
int di[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
struct Edge {
  LL to, cost;
};
struct edge {
  LL from, to, cost;
};
vector<vector<Edge>> vec;
vector<edge> ed;
vector<LL> v;
map<string, LL> ma;
set<LL> st;
void YN(bool f) {
  if (f)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
void yn(bool f) {
  if (f)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
int par[200000];
int find(int x) {
  if (par[x] == x) return x;
  par[x] = find(par[x]);
  return par[x];
}
void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  par[x] = y;
}
bool same(int x, int y) { return find(x) == find(y); }
int main() {
  cin >> n >> m;
  for (LL i = 0; i < n; i++) {
    cin >> a[i];
    d[i] = a[i];
  }
  for (int i = 0; i < n; i++) par[i] = i;
  vec.resize(n);
  for (LL i = 0; i < m; i++) {
    LL x, y, z;
    cin >> x >> y >> z;
    ed.push_back(edge{x - 1, y - 1, z});
  }
  sort(ed.begin(), ed.end(), [](edge x, edge y) { return x.cost < y.cost; });
  for (LL i = 0; i < ed.size(); i++) {
    LL u = find(ed[i].from), t = find(ed[i].to), cost = ed[i].cost;
    if (u != t)
      cost -= d[u] + d[t];
    else
      cost -= d[u];
    if (cost <= 0) {
      ans = m - i - 1;
    }
    unite(u, t);
    if (u != t) d[t] += d[u];
  }
  cout << ans << endl;
  return 0;
}
