#include <bits/stdc++.h>
using namespace std;
struct Fast {
  Fast() {
    std::cin.tie(0);
    ios::sync_with_stdio(false);
    cout.precision(20);
  }
} fast;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;
template <typename T>
inline bool chmin(T& a, const T& b) {
  if (a > b) a = b;
  return a > b;
}
template <typename T>
inline bool chmax(T& a, const T& b) {
  if (a < b) a = b;
  return a < b;
}
long long max(long long x, int y) { return max(x, (long long)y); }
long long max(int x, long long y) { return max((long long)x, y); }
long long min(long long x, int y) { return min(x, (long long)y); }
long long min(int x, long long y) { return min((long long)x, y); }
struct UnionFind {
  vector<long long> data;
  UnionFind(long long N) : data(vector<long long>(N, -1)) {}
  long long root(long long x) {
    if (data[x] < 0)
      return x;
    else
      return data[x] = root(data[x]);
  }
  bool same(long long x, long long y) { return root(x) == root(y); }
  void unite(long long x, long long y) {
    if (!same(x, y)) {
      x = root(x);
      y = root(y);
      if (data[x] < data[y]) {
        data[x] += data[y];
        data[y] = x;
      } else {
        data[y] += data[x];
        data[x] = y;
      }
    }
    return;
  }
  long long getsize(long long x) { return -data[root(x)]; }
};
signed main() {
  ll N, M;
  cin >> N >> M;
  ll X[N], A[M], B[M], C[M];
  bool use[M];
  for (long long(i) = (0); (i) < (M); (i)++) use[i] = 1;
  for (long long(i) = (0); (i) < (N); (i)++) cin >> X[i];
  for (long long(i) = (0); (i) < (M); (i)++) cin >> A[i] >> B[i] >> C[i];
  for (long long(i) = (0); (i) < (M); (i)++) A[i]--;
  for (long long(i) = (0); (i) < (M); (i)++) B[i]--;
  bool flag = 1;
  while (flag) {
    flag = 0;
    UnionFind UF(N);
    for (long long(i) = (0); (i) < (M); (i)++)
      if (use[i]) UF.unite(A[i], B[i]);
    set<ll> s;
    map<ll, ll> m;
    for (long long(i) = (0); (i) < (N); (i)++) {
      s.insert(UF.root(i));
      m[UF.root(i)] += X[i];
    }
    for (long long(i) = (0); (i) < (M); (i)++) {
      if (use[i]) {
        if (m[UF.root(A[i])] < C[i]) {
          use[i] = 0;
          flag = 1;
        }
      }
    }
  }
  ll ans = 0;
  for (long long(i) = (0); (i) < (M); (i)++)
    if (!use[i]) ans++;
  cout << ans << endl;
}
