#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};
struct Edge {
  int from, to;
  long long cost;
  Edge(int f, int t, long long c) : from(f), to(t), cost(c) {}
  bool operator<(const Edge &e) const { return cost < e.cost; }
};
long long nodes[100001];
vector<Edge> edges;
class UnionFind {
 public:
  int n;
  vector<int> par, rank;
  vector<long long> nodes_cost, max_edge_cost;
  UnionFind(int n) {
    for (int i = 0; i < n; ++i) {
      par.push_back(i);
      rank.push_back(0);
      nodes_cost.push_back(nodes[i]);
      max_edge_cost.push_back(0);
    }
  }
  int find(int x) { return ((par[x] == x) ? x : par[x] = find(par[x])); }
  int get_nodes_cost(int x) { return nodes_cost[find(x)]; }
  int get_max_edge_cost(int x) { return max_edge_cost[find(x)]; }
  void unite(Edge e) {
    int x = e.from, y = e.to;
    long long mec = max({max_edge_cost[x], max_edge_cost[y], e.cost});
    x = find(x);
    y = find(y);
    if (x == y) {
      max_edge_cost[x] = mec;
      return;
    }
    if (rank[x] < rank[y]) {
      par[x] = y;
      nodes_cost[y] += nodes[x];
      max_edge_cost[y] = mec;
    } else {
      par[y] = x;
      nodes_cost[x] += nodes[y];
      max_edge_cost[x] = mec;
      if (rank[x] == rank[y]) rank[x]++;
    }
    return;
  }
  bool is_same(int x, int y) { return find(x) == find(y); }
};
bool is_ok(UnionFind *uf, Edge *e) {
  int i = e->from, j = e->to;
  return uf->get_nodes_cost(i) > uf->get_max_edge_cost(i) &&
         uf->get_nodes_cost(j) > uf->get_max_edge_cost(j);
}
int main() {
  std::ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m, a, b;
  long long c;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> nodes[i];
  for (int i = 0; i < m; ++i) {
    cin >> a >> b >> c;
    edges.push_back(Edge(a - 1, b - 1, c));
  }
  sort(edges.begin(), edges.end());
  UnionFind uf = UnionFind(n);
  int ans = m;
  for (int i = 0; i < m; ++i) {
    Edge e = edges[i];
    uf.unite(e);
    if (is_ok(&uf, &e)) {
      ans = m - 1 - i;
    }
  }
  cout << ans << endl;
}
