#include <bits/stdc++.h>
using namespace std;
long long mi[100100];
long long we[100100];
bool used[100100];
struct unionf {
  vector<long long> data;
  unionf(int size) : data(size, -1) {}
  bool unions(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (data[y] < data[x]) {
        int d = x;
        x = y;
        y = d;
      }
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool finds(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  long long find(int x) { return -data[x]; }
  void set(int x, long long y) { data[x] = -y; }
};
vector<int> gr[100100];
vector<pair<int, long long> > eve[100100];
vector<pair<long long, pair<int, int> > > ed;
long long cal(int ti, int v) {
  while (1) {
    pair<int, long long> now = make_pair(ti + 1, -123456789012345678L);
    int p = lower_bound(eve[v].begin(), eve[v].end(), now) - eve[v].begin();
    p--;
    if (eve[v][p].second > 0)
      return eve[v][p].second;
    else
      v = -eve[v][p].second;
  }
}
int main() {
  int n, m, a, b;
  long long inf = 1001001001, x;
  cin >> n >> m;
  unionf uni(n + 10);
  for (int i = 0; i < n; i++) {
    cin >> we[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> x;
    a--;
    b--;
    ed.push_back(make_pair(x, make_pair(a, b)));
  }
  sort(ed.begin(), ed.end());
  for (int i = 0; i < n; i++) eve[i].push_back(make_pair(-1, we[i]));
  for (int i = 0; i < m; i++) {
    x = ed[i].first;
    a = ed[i].second.second;
    b = ed[i].second.first;
    int y = uni.root(a), z = uni.root(b);
    if (!uni.finds(a, b)) {
      uni.unions(a, b);
      int w = uni.root(a);
      if (y == w) swap(y, z);
      assert(w == z);
      we[z] += we[y];
      eve[y].push_back(make_pair(i, -uni.root(z)));
      eve[z].push_back(make_pair(i, we[z]));
      used[i] = true;
      gr[a].push_back(b);
      gr[b].push_back(a);
    }
  }
  for (int i = 0; i < n; i++) eve[i].push_back(make_pair(100100, we[i]));
  for (int i = 0; i < n; i++) {
  }
  int ti = m, out = 0;
  for (int i = m - 1; i >= 0; i--) {
    if (cal(ti, ed[i].second.second) < ed[i].first) {
      out++;
      if (used[i]) ti = i - 1;
    }
  }
  cout << out << endl;
}
