#include <bits/stdc++.h>
using namespace std;
const long long int E = 1e18 + 7;
const long long int MOD = 1000000007;
vector<pair<long long int, long long int>> uft;
long long int parent(long long int a) {
  return uft[a].first == a ? a : uft[a].first = parent(uft[a].first);
}
void merge(long long int p, long long int c) {
  if (parent(p) == parent(c)) {
    return;
  }
  uft[parent(p)].second += uft[parent(c)].second;
  uft[parent(c)].first = parent(p);
}
int main() {
  long long int n, m;
  cin >> n >> m;
  vector<long long int> X(n);
  for (auto &I : X) {
    cin >> I;
  }
  uft.resize(n + m);
  for (int i = 0; i < n; i++) {
    uft[i] = {i, X[i]};
  }
  for (int i = 0; i < m; i++) {
    uft[i + n] = {i + n, 0};
  }
  vector<pair<long long int, pair<long long int, long long int>>> edge(m);
  for (auto &I : edge) {
    cin >> I.second.first >> I.second.second >> I.first;
    I.second.first--;
    I.second.second--;
  }
  sort(edge.begin(), edge.end());
  vector<pair<long long int, long long int>> children(m, {-1, -1});
  vector<bool> used(m, false);
  for (int i = 0; i < m; i++) {
    if (parent(edge[i].second.first) == parent(edge[i].second.second)) {
      continue;
    }
    used[i] = true;
    if (parent(edge[i].second.first) >= n &&
        uft[parent(edge[i].second.first)].second <
            edge[parent(edge[i].second.first) - n].first) {
      children[i].first = parent(edge[i].second.first) - n;
    }
    if (parent(edge[i].second.second) >= n &&
        uft[parent(edge[i].second.second)].second <
            edge[parent(edge[i].second.second) - n].first) {
      children[i].second = parent(edge[i].second.second) - n;
    }
    merge(i + n, edge[i].second.first);
    merge(i + n, edge[i].second.second);
  }
  if (uft[parent(0)].second < edge[parent(0) - n].first) {
    queue<long long int> Q;
    Q.push(parent(0) - n);
    while (!Q.empty()) {
      long long int w = Q.front();
      Q.pop();
      used[w] = false;
      if (children[w].first != -1) {
        Q.push(children[w].first);
      }
      if (children[w].second != -1) {
        Q.push(children[w].second);
      }
    }
  }
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    uft[i] = {i, X[i]};
  }
  for (int i = 0; i < m; i++) {
    if (used[i]) {
      ans++;
      merge(edge[i].second.first, edge[i].second.second);
    }
  }
  for (int i = 0; i < m; i++) {
    if (!used[i]) {
      if (parent(edge[i].second.first) == parent(edge[i].second.second) &&
          uft[parent(edge[i].second.second)].second >= edge[i].first) {
        ans++;
      }
    }
  }
  cout << m - ans << endl;
  return 0;
}
