#include <bits/stdc++.h>
using namespace std;
class DSU {
 private:
  vector<long long> parents;
  vector<long long> sizes;

 public:
  DSU(long long n) {
    parents.resize(n + 1);
    for (long long i = 1; i <= n; ++i) parents[i] = i;
    sizes.resize(n + 1);
    for (long long i = 1; i <= n; ++i) sizes[i] = 1;
  }
  long long root(long long i) {
    while (parents[i] != i) {
      parents[i] = parents[parents[i]];
      i = parents[i];
    }
    return i;
  }
  bool find(long long a, long long b) { return root(a) == root(b); }
  void join(long long a, long long b) {
    long long root_a = root(a);
    long long root_b = root(b);
    if (root_a == root_b) return;
    if (sizes[root_a] < sizes[root_b]) {
      parents[root_a] = parents[root_b];
      sizes[root_b] += sizes[root_a];
    } else {
      parents[root_b] = parents[root_a];
      sizes[root_a] += sizes[root_b];
    }
  }
  vector<vector<long long>> getComponents() {
    long long n = parents.size() - 1;
    vector<bool> seen(n + 1);
    vector<vector<long long>> ret;
    for (long long i = 1; i <= n; ++i) {
      if (!seen[i]) {
        vector<long long> component;
        long long curroot = root(i);
        for (long long j = 1; j <= n; ++j) {
          if (root(j) == curroot) {
            seen[j] = true;
            component.push_back(j);
          }
        }
        ret.push_back(component);
      }
    }
    return ret;
  }
};
struct edge {
  long long dest;
  long long weight;
};
edge make_edge(long long d, long long w) {
  edge e;
  e.dest = d;
  e.weight = w;
  return e;
}
long long solve(vector<vector<edge>>& graph, vector<long long>& x,
                vector<long long>& component) {
  if (component.size() == 1) return 0;
  long long ret = 0;
  long long vertexSum = 0;
  for (long long v : component) {
    vertexSum += x[v];
  }
  long long numVs = component.size();
  unordered_map<long long, long long> compmap;
  for (long long i = 1; i <= numVs; ++i) {
    compmap[component[i - 1]] = i;
  }
  DSU dsu(numVs);
  for (long long ci = 0; ci < numVs; ++ci) {
    long long c = component[ci];
    vector<edge>& edges = graph[c];
    long long numEdges = edges.size();
    for (long long i = numEdges - 1; i >= 0; --i) {
      if (edges[i].weight > vertexSum) {
        ret++;
        edges.erase(edges.begin() + i);
      } else {
        dsu.join(ci + 1, compmap[edges[i].dest]);
      }
    }
  }
  if (ret > 0) {
    auto newcomponents = dsu.getComponents();
    for (vector<long long>& newcomponent : newcomponents) {
      for (long long& nc : newcomponent) {
        nc = component[nc - 1];
      }
      ret += solve(graph, x, newcomponent);
    }
  }
  return ret;
}
int32_t main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> x(n + 1);
  for (long long i = 1; i <= n; ++i) cin >> x[i];
  vector<vector<edge>> graph(n + 1, vector<edge>());
  DSU dsu(n);
  for (long long i = 0; i < m; ++i) {
    long long a, b, y;
    cin >> a >> b >> y;
    graph[a].push_back(make_edge(b, y));
    dsu.join(a, b);
  }
  auto comps = dsu.getComponents();
  long long ret = 0;
  for (vector<long long>& component : comps) {
    ret += solve(graph, x, component);
  }
  cout << ret << endl;
  return 0;
}
