#include <bits/stdc++.h>
using namespace std;
const int maxn = 100002;
int n, m, ans, x[maxn], a[maxn], b[maxn], y[maxn];
bool ban[maxn];
vector<vector<int> > g;
long long getSum(int u, vector<bool>& vis) {
  vis[u] = true;
  long long res = x[u];
  for (int i = 0; i < g[u].size(); ++i)
    if (!ban[g[u][i]]) {
      int v = a[g[u][i]] + b[g[u][i]] - u;
      if (!vis[v]) res += getSum(v, vis);
    }
  return res;
}
void delEdge(int u, long long lim, vector<bool>& vis) {
  vis[u] = true;
  for (int i = 0; i < g[u].size(); ++i) {
    int idx = g[u][i];
    if (!ban[idx]) {
      if (y[idx] > lim) {
        ban[idx] = true;
        ++ans;
      }
      int v = a[idx] + b[idx] - u;
      if (!vis[v]) delEdge(v, lim, vis);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> x[i];
  g = vector<vector<int> >(n);
  for (int i = 0; i < m; ++i) {
    cin >> a[i] >> b[i] >> y[i];
    --a[i];
    --b[i];
    g[a[i]].push_back(i);
    g[b[i]].push_back(i);
  }
  while (true) {
    int old = ans;
    vector<bool> vis(n);
    for (int i = 0; i < n; ++i)
      if (!vis[i]) {
        long long tot = getSum(i, vis);
        if (tot > 0) {
          vector<bool> vis2(n);
          delEdge(i, tot, vis2);
        }
      }
    if (ans == old) break;
  }
  cout << ans << endl;
  return 0;
}
