#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;
int n, m;
int cnt[N];
int a[N], b[N], c[N];
pair<int, int> p[N];
vector<int> g[N];
bool used[N];
int parent[N], sz[N], edge[N];
long long sum[N];
bool mark[N];
int findher(int a) {
  if (a == parent[a]) return a;
  return parent[a] = findher(parent[a]);
}
void tmerge(int a, int b) {
  a = findher(a);
  b = findher(b);
  if (sz[a] < sz[b]) swap(a, b);
  parent[b] = a;
  sum[a] += sum[b];
  sz[a] += sz[b];
  edge[a] += edge[b];
  for (int j = 0; j < (int)g[b].size(); j++) {
    g[a].push_back(g[b][j]);
  }
  g[b].clear();
}
int f(int ind) {
  for (int i = 1; i <= n; i++) {
    parent[i] = i;
    sum[i] = cnt[i];
    sz[i] = 1;
    g[i].push_back(i);
    edge[i] = 0;
  }
  for (int i = 1; i <= ind; i++) {
    int id = p[i].second;
    int aa = a[id], bb = b[id];
    if (findher(aa) != findher(bb)) {
      tmerge(aa, bb);
    }
    int p = findher(aa);
    edge[p]++;
  }
  int answ = 0;
  for (int i = ind; i >= 1; i--) {
    int v = a[p[i].second];
    if (mark[i] && used[v] == false) {
      v = findher(v);
      answ += edge[v];
      for (int j = 0; j < (int)g[v].size(); j++) {
        int to = g[v][j];
        used[to] = true;
      }
    }
  }
  return answ;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &cnt[i]);
    parent[i] = i;
    sum[i] = cnt[i];
    sz[i] = 1;
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &a[i], &b[i], &c[i]);
    p[i] = make_pair(c[i], i);
  }
  sort(p + 1, p + m + 1);
  int ind = -1;
  vector<int> mas;
  for (int i = 1; i <= m; i++) {
    int id = p[i].second;
    int aa = a[id], bb = b[id];
    if (findher(aa) != findher(bb)) {
      tmerge(aa, bb);
    }
    int P = findher(aa);
    ++edge[P];
    if (sum[P] >= 1ll * c[id]) {
      mark[i] = true;
      mas.push_back(i);
      ind = i;
    }
  }
  if (ind == -1) {
    cout << m << endl;
    return 0;
  }
  int ina = 0, inb = (int)mas.size() - 1;
  int answ = 0;
  for (int i = 0; i < (int)mas.size(); i++) {
    answ = max(answ, f(mas[i]));
  }
  cout << m - answ << endl;
  return 0;
}
