#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
int ran[100010], par[100010], ti[100010], x[100010];
vector<pii> sz[100010];
set<pair<pair<int, pii>, int>> s;
pair<int, pair<int, int>> p[100010];
void init(int n) {
  for (int i = 0; i < n; i++) {
    ran[i] = x[i];
    par[i] = i;
    ti[i] = 1000000000;
    sz[i].push_back({0, 1});
  }
}
int find(int x, int t) {
  if (ti[x] > t)
    return x;
  else
    return find(par[x], t);
}
void unite(int x, int y, int t) {
  x = find(x, t);
  y = find(y, t);
  if (x == y) return;
  if (ran[x] < ran[y]) swap(x, y);
  ran[x] += ran[y];
  par[y] = x;
  ti[y] = t;
  sz[x].push_back({t, ran[x]});
}
int size(int x, int t) {
  x = find(x, t);
  int l = -1, r = sz[x].size();
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (sz[x][mid].first <= t)
      l = mid;
    else
      r = mid;
  }
  return sz[x][l].second;
}
bool same(int x, int y, int t) { return find(x, t) == find(y, t); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i, n, m;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> x[i];
  }
  init(n);
  for (i = 0; i < m; i++) {
    int a, b, w;
    cin >> a >> b >> w;
    a--;
    b--;
    p[i] = {w, {a, b}};
  }
  sort(p, p + m);
  for (i = 0; i < m; i++) {
    unite(p[i].second.first, p[i].second.second, i + 1);
    s.insert({p[i], i + 1});
  }
  int ans = 0;
  while (s.size()) {
    auto p = *s.rbegin();
    int t = p.second, u = p.first.second.first, w = p.first.first;
    if (size(u, t) < w) {
      s.erase(p);
    } else {
      vector<pair<pair<int, pii>, int>> v;
      auto it = s.begin();
      while (it != s.end()) {
        auto x = *it;
        int a = x.first.second.first, b = x.first.second.second;
        if (same(u, a, t) && same(u, b, t)) {
          ans++;
          v.push_back(x);
        }
        it++;
      }
      for (i = 0; i < v.size(); i++) {
        s.erase(v[i]);
      }
      v.clear();
    }
  }
  cout << m - ans << endl;
}
