#include <bits/stdc++.h>
using namespace std;
int N, M, X[100000], A, B, Y, g[100000], cnt;
long long c[100000];
bool b = true;
vector<pair<int, int> > v[100000];
void dfs(int x, int k) {
  g[x] = k;
  c[k] += X[x];
  for (int i = 0; i != v[x].size(); ++i) {
    if (g[v[x][i].first] == -1) {
      dfs(v[x][i].first, k);
    }
  }
}
int main() {
  cin >> N >> M;
  for (int i = 0; i != N; ++i) cin >> X[i];
  for (int i = 0; i != M; ++i) {
    cin >> A >> B >> Y;
    --A;
    --B;
    v[A].push_back(make_pair(B, Y));
    v[B].push_back(make_pair(A, Y));
  }
  while (b) {
    b = false;
    memset(g, -1, sizeof g);
    for (int i = 0; i != N; ++i) {
      if (g[i] == -1) {
        c[i] = 0;
        dfs(i, i);
      }
    }
    for (int i = 0; i != N; ++i) {
      for (int j = 0; j != v[i].size(); ++j) {
        if (v[i][j].second > c[g[i]]) {
          swap(v[i][j], v[i][v[i].size() - 1]);
          v[i].pop_back();
          --j;
          ++cnt;
          b = true;
        }
      }
    }
  }
  cout << cnt / 2 << endl;
}
