#include <bits/stdc++.h>
using namespace std;
template <class T>
void print(vector<T> s) {
  for (T i : s) cout << i << " ";
  cout << endl;
}
const int maxn = 1e5 + 7;
int aaaasds[maxn], asdfdsf[maxn];
int getPrev(int v) {
  if (v == aaaasds[v]) return v;
  aaaasds[v] = getPrev(aaaasds[v]);
  return aaaasds[v];
}
long long summa[maxn];
void join(int a, int b) {
  a = getPrev(a);
  b = getPrev(b);
  if (a == b) return;
  if (asdfdsf[a] < asdfdsf[b]) swap(a, b);
  aaaasds[b] = a;
  summa[a] += summa[b];
  if (asdfdsf[a] == asdfdsf[b]) asdfdsf[a]++;
}
long long kek[maxn];
vector<pair<int, int> > g[maxn];
bool ok[maxn];
void dfs(int v, long long x) {
  ok[v] = 1;
  for (pair<int, int> u : g[v]) {
    if (!ok[u.second] && u.first <= x) dfs(u.second, x);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  freopen("test.in", "r", stdin);
  int n, m;
  cin >> n >> m;
  vector<int> s(n);
  for (int i = 0; i < n; i++) cin >> s[i];
  vector<pair<int, pair<int, int> > > lst(m);
  for (int i = 0; i < m; i++) {
    int a, b, x;
    cin >> a >> b >> x;
    lst[i] = {x, {a - 1, b - 1}};
    g[a - 1].push_back({x, b - 1});
    g[b - 1].push_back({x, a - 1});
  }
  sort(lst.begin(), lst.end());
  for (int i = 0; i < n; i++) {
    aaaasds[i] = i;
    summa[i] = s[i];
  }
  for (int i = 0; i < m; i++) {
    join(lst[i].second.first, lst[i].second.second);
    kek[i] = summa[getPrev(lst[i].second.first)];
  }
  int answer = 0;
  for (int i = m - 1; i >= 0; i--) {
    int a = lst[i].second.first, b = lst[i].second.second;
    if (ok[a] && ok[b]) {
      answer++;
      continue;
    }
    if (lst[i].first <= kek[i]) {
      answer++;
      dfs(a, kek[i]);
    }
  }
  cout << m - answer << endl;
  return 0;
}
