#include <bits/stdc++.h>
using namespace std;
vector<int> X;
vector<vector<pair<int, int>>> graph;
vector<int> visited;
vector<int> lis;
int weight(int i) {
  if (visited[i]) return 0;
  visited[i] = 1;
  lis.push_back(i);
  int ans = X[i];
  for (auto p : graph[i]) {
    if (!visited[p.first]) {
      ans += weight(p.first);
    }
  }
  return ans;
}
int recur(int i) {
  int ans = 0;
  lis = vector<int>();
  int w = weight(i);
  for (int i : lis) {
    for (int j = 0; j < graph[i].size();) {
      if (graph[i][j].second > w) {
        swap(graph[i][j], graph[i].back());
        graph[i].pop_back();
        ans++;
      } else {
        j++;
      }
    }
  }
  return ans / 2;
}
int main() {
  int N, M;
  cin >> N >> M;
  X.resize(N);
  for (int& x : X) cin >> x;
  graph.resize(N);
  for (int i = 0; i < M; i++) {
    int a, b, y;
    cin >> a >> b >> y;
    a--, b--;
    graph[a].emplace_back(b, y);
    graph[b].emplace_back(a, y);
  }
  int ans = 0;
  for (;;) {
    int cnt = 0;
    visited = vector<int>(N);
    for (int i = 0; i < N; i++) {
      if (!visited[i]) cnt += recur(i);
    }
    if (cnt == 0) break;
    ans += cnt;
  }
  cout << ans << endl;
  return 0;
}
