#include <bits/stdc++.h>
using namespace std;
int par[100010];
int myrank[100010];
long long value[100010];
int N, M;
int x[101000];
map<pair<int, int>, long long> m;
void init(int n) {
  for (int i = 0; i < n; i++) {
    par[i] = i;
    myrank[i] = 0;
    value[i] = x[i];
  }
}
int find(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}
void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  if (myrank[x] < myrank[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (myrank[x] == myrank[y]) myrank[x]++;
  }
  value[x] += value[y];
  value[y] = value[x];
}
bool same(int x, int y) { return find(x) == find(y); }
int main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < M; i++) {
    int a, b;
    long long yy;
    cin >> a >> b >> yy;
    a--;
    b--;
    m[pair<int, int>(a, b)] = yy;
  }
  int res = 0;
  bool change = true;
  while (change) {
    init(N);
    for (auto i = m.begin(); i != m.end(); i++) {
      pair<int, int> edg = i->first;
      unite(edg.first, edg.second);
    }
    change = false;
    vector<pair<int, int> > delete_list;
    for (auto i = m.begin(); i != m.end(); i++) {
      pair<int, int> edg = i->first;
      long long w = i->second;
      long long w_sum = max(value[find(edg.first)], value[find(edg.second)]);
      if (w > w_sum) {
        change = true;
        delete_list.emplace_back(edg);
        res++;
      }
    }
    for (int i = 0; i < delete_list.size(); i++) {
      m.erase(delete_list[i]);
    }
  }
  cout << res << endl;
  return 0;
}
