#include <bits/stdc++.h>
using namespace std;
int ed[101010];
long long x[101010], y[101010];
pair<long long, int> yy[101010];
int n, m, u[101010], v[101010];
int main() {
  cin >> n >> m;
  int xn = 0;
  for (int i = (int)0; i < (int)n; i++) {
    cin >> x[i];
    xn += x[i];
  }
  for (int i = (int)0; i < (int)m; i++) {
    cin >> u[i] >> v[i] >> y[i];
    --u[i];
    --v[i];
    ed[u[i]]++;
    ed[v[i]]++;
    yy[i] = make_pair(y[i], i);
  }
  sort(yy, yy + m);
  int ans = 0;
  for (int i = m - 1; i >= 0; i--) {
    if (yy[i].first <= xn) break;
    ans++;
    ed[u[yy[i].second]]--;
    ed[v[yy[i].second]]--;
    if (ed[u[yy[i].second]] <= 0) xn -= x[u[yy[i].second]];
    if (ed[v[yy[i].second]] <= 0) xn -= x[v[yy[i].second]];
  }
  cout << ans << endl;
  return 0;
}
