#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const long long LINF = 1e18;
const int MOD = 1e9 + 7;
int par[100001], rnk[100001];
long long vsum[100001], maxedge[100001];
vector<pair<long long, pair<int, int>>> g;
int n, m;
long long X[100001];
void init(int n) {
  for (int i = 0; i < n; i++) {
    par[i] = i;
    rnk[i] = 0;
    vsum[i] = X[i];
    maxedge[i] = 0;
  }
}
int find(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}
void unite(int x, int y, long long cost) {
  x = find(x);
  y = find(y);
  if (x == y) {
    maxedge[x] = max(maxedge[x], cost);
  } else if (rnk[x] < rnk[y]) {
    par[x] = y;
    maxedge[y] = max(maxedge[x], maxedge[y]);
    maxedge[y] = max(maxedge[y], cost);
    vsum[y] += vsum[x];
  } else {
    par[y] = x;
    maxedge[x] = max(maxedge[x], maxedge[y]);
    maxedge[x] = max(maxedge[x], cost);
    vsum[x] += vsum[y];
    if (rnk[x] == rnk[y]) rnk[x]++;
  }
}
bool same(int x, int y) { return find(x) == find(y); }
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> X[i];
  for (int i = 0; i < m; i++) {
    int a, b;
    long long y;
    cin >> a >> b >> y;
    a--;
    b--;
    if (a > b) swap(a, b);
    g.push_back(pair<long long, pair<int, int>>(y, pair<int, int>(a, b)));
  }
  init(n);
  sort(g.begin(), g.end());
  bool ok = true;
  int ans = m;
  for (int i = 0; i < g.size(); i++) {
    pair<long long, pair<int, int>> e = g[i];
    long long cost = e.first;
    int a = e.second.first, b = e.second.second;
    unite(a, b, cost);
    a = find(a);
    ok = (vsum[a] >= maxedge[a]);
    if (ok) {
      ans = m - i - 1;
    }
  }
  cout << (ans) << endl;
}
