#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool setmin(T& a, T b) {
  if (b < a) {
    a = b;
    return true;
  } else {
    return false;
  }
}
template <typename T>
bool setmax(T& a, T b) {
  if (b > a) {
    a = b;
    return true;
  } else {
    return false;
  }
}
template <typename T>
bool setmineq(T& a, T b) {
  if (b <= a) {
    a = b;
    return true;
  } else {
    return false;
  }
}
template <typename T>
bool setmaxeq(T& a, T b) {
  if (b >= a) {
    a = b;
    return true;
  } else {
    return false;
  }
}
template <typename T>
T gcd(T a, T b) {
  return (b == 0 ? a : gcd(b, a % b));
}
template <typename T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
const int M = 100000;
long long signed int S[M];
struct UnionFind {
  int s, num;
  vector<vector<int>> v;
  vector<int> find;
  UnionFind() { s = 0; }
  UnionFind(int s) { init(s); }
  void init(int arg_s) {
    num = s = arg_s;
    v.clear();
    find.clear();
    for (int i = (0); i < (s); i++) {
      v.push_back({i});
      find.push_back(i);
    }
  }
  bool unite(int x, int y) {
    assert(((0) <= (x) && (x) < (s)) && ((0) <= (y) && (y) < (s)));
    if (find[x] == find[y]) {
      return false;
    }
    num--;
    if (v[find[x]].size() > v[find[y]].size()) {
      swap(x, y);
    }
    int fx = find[x];
    S[v[find[y]][0]] += S[v[find[x]][0]];
    for (auto&& e : v[fx]) {
      v[find[y]].push_back(e);
      find[e] = find[y];
    }
    v[fx].clear();
    return true;
  }
};
long long signed int n, m, x[M], a[M], b[M], y[M];
bool used[M];
vector<array<long long signed int, 3>> e;
int main() {
  cin >> n >> m;
  for (int i = (0); i < (n); i++) {
    cin >> x[i];
  }
  for (int i = (0); i < (m); i++) {
    cin >> a[i] >> b[i] >> y[i];
    a[i]--;
    b[i]--;
  }
  for (int i = (0); i < (m); i++) {
    e.push_back({y[i], a[i], b[i]});
  }
  sort(e.begin(), e.end());
  UnionFind uf(n);
  for (int i = (0); i < (n); i++) {
    S[i] = x[i];
  }
  int ans = m;
  bool f = true;
  while (f) {
    f = false;
    for (int i = (0); i < (m); i++) {
      if (used[i]) {
        continue;
      }
      long long signed int Y = e[i][0];
      long long signed int A = e[i][1];
      long long signed int B = e[i][2];
      long long signed int SA = S[uf.v[uf.find[A]][0]];
      long long signed int SB = S[uf.v[uf.find[B]][0]];
      if (Y <= SA + SB) {
        uf.unite(A, B);
        used[i] = true;
        f = true;
        ans--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
