#include <bits/stdc++.h>
using namespace std;
long long dfs(int i, vector<int>& x, vector<map<int, int>>& e, int t,
              vector<int>& o) {
  long long r = x[i];
  o[i] = t;
  for (auto& f : e[i]) {
    if (o[f.first]) continue;
    r += dfs(f.first, x, e, t, o);
  }
  return r;
}
int visit(int n, int i, vector<int>& x, vector<map<int, int>>& e,
          vector<int>& o, long long w, int t) {
  int r = 0;
  for (decltype(n) j = (0); j < (n); ++j) {
    if (o[j] != t) continue;
    for (auto it = e[j].begin(); it != e[j].end();)
      if (it->second > w) {
        it = e[j].erase(it);
        ++r;
      } else
        ++it;
  }
  vector<int> p(n);
  long long v = dfs(i, x, e, i + 1, p);
  if (v == w) return r;
  r += visit(n, i, x, e, p, v, i + 1);
  for (decltype(n) j = (0); j < (n); ++j) {
    if (o[j] != t) continue;
    if (p[j]) continue;
    long long v = dfs(j, x, e, j + 1, p);
    r += visit(n, j, x, e, p, v, j + 1);
  }
  return r;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> x(n);
  for (int& i : x) cin >> i;
  vector<map<int, int>> e(n);
  for (decltype(m) i = (0); i < (m); ++i) {
    int a, b, y;
    cin >> a >> b >> y;
    --a, --b;
    e[a][b] = y;
    e[b][a] = y;
  }
  vector<int> o(n);
  long long w = dfs(0, x, e, 1, o);
  auto r = visit(n, 0, x, e, o, w, 1) / 2;
  cout << r << endl;
  return 0;
}
