#include <bits/stdc++.h>
using namespace std;
struct union_find {
  int rnk[100001], par[100001];
  union_find(int n) {
    for (int i = 0; i < n; i++) rnk[i] = 1, par[i] = i;
  }
  int find(int x) {
    if (x == par[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 (rnk[x] > rnk[y])
      par[y] = x;
    else {
      par[x] = y;
      if (rnk[x] == rnk[y]) rnk[y]++;
    }
  }
  bool same(int x, int y) {
    x = find(x);
    y = find(y);
    return x == y;
  }
};
struct Edge {
  int to, cost;
};
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> X(N);
  vector<vector<Edge>> Y(N);
  set<tuple<int, int, int>> P;
  long long sumw = 0;
  for (int i = 0; i < N; i++) {
    cin >> X[i];
    sumw += X[i];
  }
  int rem = 0;
  int a, b, y;
  for (int i = 0; i < M; i++) {
    cin >> a >> b >> y;
    if (y > sumw) {
      rem++;
      continue;
    }
    a--;
    b--;
    P.insert(make_tuple(a, b, y));
  }
  for (;;) {
    union_find uf(N);
    int oldrem = rem;
    for (auto& p : P) {
      uf.unite(get<0>(p), get<1>(p));
    }
    map<int, long long> sumc;
    for (int i = 0; i < N; i++) {
      sumc[uf.find(i)] += X[i];
    }
    for (auto& p : P) {
      int ey = get<2>(p);
      if (sumc[uf.find(get<0>(p))] < ey || sumc[uf.find(get<1>(p))] < ey) {
        P.erase(p);
        rem++;
      }
    }
    if (oldrem == rem) break;
  }
  cout << rem << endl;
  return 0;
}
