#include <bits/stdc++.h>
using namespace std;
vector<long long> X;
struct UnionFind {
  vector<int> par;
  vector<int> sizes;
  vector<long long> Xsum;
  vector<long long> Ymax;
  UnionFind(int n) : par(n), sizes(n, 1), Xsum(n), Ymax(n) {
    for (int i = 0; i < n; i++) par[i] = i;
    for (int i = 0; i < n; i++) Xsum[i] = X[i];
  }
  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);
  }
  void unite(int x, int y, long long w) {
    x = find(x);
    y = find(y);
    if (sizes[x] < sizes[y]) swap(x, y);
    if (x == y) {
      Ymax[x] = max(Ymax[x], w);
      return;
    }
    par[y] = x;
    sizes[x] += sizes[y];
    Xsum[x] += Xsum[y];
    Ymax[x] = max({Ymax[x], Ymax[y], w});
  }
  bool pre_unite(int x, int y, long long w) {
    x = find(x);
    y = find(y);
    if (sizes[x] < sizes[y]) swap(x, y);
    if (x == y) {
      if (Xsum[x] < max(Ymax[x], w))
        return false;
      else
        return true;
    }
    if (Xsum[x] + Xsum[y] < max({Ymax[x], Ymax[y], w}))
      return false;
    else
      return true;
  }
  bool is_ok(int x, int y) {
    x = find(x);
    y = find(y);
    if (sizes[x] < sizes[y]) swap(x, y);
    if (Xsum[x] < Ymax[x])
      return false;
    else
      return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return sizes[find(x)]; }
};
int main() {
  int N, M;
  cin >> N >> M;
  X.resize(N);
  for (int i = 0; i < N; i++) cin >> X[i];
  unordered_map<long long, vector<pair<int, int>>> Emap;
  for (int i = 0; i < M; i++) {
    int a, b;
    long long y;
    cin >> a >> b >> y;
    a--;
    b--;
    Emap[y].push_back(make_pair(a, b));
  }
  vector<pair<long long, int>> id;
  vector<vector<pair<int, int>>> E(M);
  int index = 0;
  for (auto m : Emap) {
    id.push_back(make_pair(m.first, index));
    E[index] = m.second;
    index++;
  }
  int size = index;
  sort(id.begin(), id.end());
  UnionFind uf(N);
  int ans = 0;
  vector<pair<int, int>> dame;
  for (int i = 0; i < size; i++) {
    int index = id[i].second;
    while (1) {
      bool flag = true;
      for (int j2 = 0; j2 < E[index].size(); j2++) {
        int j = j2;
        int a, b;
        a = E[index][j].first;
        b = E[index][j].second;
        if (uf.pre_unite(a, b, id[i].first)) {
          ans++;
          uf.unite(a, b, id[i].first);
          flag = false;
          swap(E[index][j2], E[index].back());
          E[index].pop_back();
          j2--;
        }
      }
      if (flag) break;
    }
    for (int j2 = 0; j2 < E[index].size(); j2++) {
      int j = j2;
      int a, b;
      a = E[index][j].first;
      b = E[index][j].second;
      uf.unite(a, b, id[i].first);
    }
    for (int j2 = 0; j2 < dame.size(); j2++) {
      int j = j2;
      int a, b;
      a = dame[j].first;
      b = dame[j].second;
      if (uf.is_ok(a, b)) {
        swap(dame[j], dame.back());
        dame.pop_back();
        j2--;
        ans++;
      }
    }
    for (int j2 = 0; j2 < E[index].size(); j2++) {
      int j = j2;
      int a, b;
      a = E[index][j].first;
      b = E[index][j].second;
      if (uf.is_ok(a, b)) {
        ans++;
      } else
        dame.push_back(make_pair(a, b));
    }
  }
  cout << M - ans << endl;
  return 0;
}
