#include <bits/stdc++.h>
using namespace std;
class UnionFindTree {
 private:
  int n;
  int groupNum;
  vector<int> parent;
  vector<int> rank;
  vector<int> num;
  int find(int i) {
    if (parent[i] == i)
      return i;
    else
      return parent[i] = find(parent[i]);
  }

 public:
  UnionFindTree(int n) {
    this->n = n;
    groupNum = n;
    parent.resize(n);
    for (int i = 0; i < n; ++i) parent[i] = i;
    rank.assign(n, 0);
    num.assign(n, 1);
  }
  void unite(int a, int b) {
    if ((a = find(a)) != (b = find(b))) {
      if (rank[a] < rank[b]) {
        parent[a] = b;
        num[b] += num[a];
      } else {
        parent[b] = a;
        if (rank[a] == rank[b]) ++rank[a];
        num[a] += num[b];
      }
      --groupNum;
    }
  }
  bool same(int a, int b) { return find(a) == find(b); }
  int getNum() { return groupNum; }
  int getNum(int a) { return num[find(a)]; }
  void getGroup(vector<vector<int> >& group) {
    map<int, int> index;
    group.clear();
    for (int i = 0; i < n; ++i) {
      int a = find(i);
      if (index.find(a) == index.end()) {
        index[a] = group.size();
        group.resize(group.size() + 1);
      }
      group[index[a]].push_back(i);
    }
  }
};
class Edge {
 public:
  int to, weight;
  Edge() {}
  Edge(int to, int weight) {
    this->to = to;
    this->weight = weight;
  }
};
vector<int> x;
vector<vector<Edge> > edges;
int solve(const vector<int>& node) {
  int n = node.size();
  long long sum = 0;
  map<int, int> index;
  for (int i = 0; i < n; ++i) {
    sum += x[node[i]];
    index[node[i]] = i;
  }
  int cnt = 0;
  UnionFindTree uft(n);
  for (int a : node) {
    for (const Edge& e : edges[a]) {
      int b = e.to;
      if (b > a || index.find(b) == index.end()) continue;
      if (e.weight <= sum) {
        uft.unite(index[a], index[b]);
        ++cnt;
      }
    }
  }
  if (uft.getNum() == 1) return cnt;
  vector<vector<int> > group;
  uft.getGroup(group);
  int ans = 0;
  for (vector<int>& v : group) {
    for (int& a : v) a = node[a];
    ans += solve(v);
  }
  return ans;
}
int main() {
  int n, m;
  cin >> n >> m;
  x.resize(n);
  for (int i = 0; i < n; ++i) cin >> x[i];
  edges.resize(n);
  for (int i = 0; i < m; ++i) {
    int a, b, y;
    cin >> a >> b >> y;
    --a;
    --b;
    edges[a].push_back(Edge(b, y));
    edges[b].push_back(Edge(a, y));
  }
  vector<int> node(n);
  for (int i = 0; i < n; ++i) node[i] = i;
  cout << (m - solve(node)) << endl;
  return 0;
}
