#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
struct Edge {
  int u;
  int v;
  long long int cost;
};
struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) {}
  bool unionSet(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
};
int main() {
  int N, M;
  cin >> N >> M;
  vector<long long int> xs(N);
  for (int i = 0; i < N; ++i) scanf("%lld", &xs[i]);
  vector<Edge> es;
  for (int i = 0; i < M; ++i) {
    int a, b, y;
    scanf("%d %d %d", &a, &b, &y);
    a--;
    b--;
    es.push_back(Edge{a, b, y});
  }
  sort(es.begin(), es.end(),
       [](const Edge& l, const Edge& r) { return l.cost < r.cost; });
  int valid_num = N;
  int answer = 0;
  UnionFind uf(N);
  vector<pair<long long int, long long int>> ps(N);
  for (int i = 0; i < N; ++i) {
    ps[i] = make_pair(0, xs[i]);
  }
  for (int i = 0; i < M; ++i) {
    auto e(es[i]);
    int l_id = uf.root(e.u);
    int r_id = uf.root(e.v);
    if (l_id != r_id) {
      auto lp(ps[l_id]);
      auto rp(ps[r_id]);
      if (lp.first <= lp.second) {
        valid_num -= uf.size(l_id);
      }
      if (rp.first <= rp.second) {
        valid_num -= uf.size(r_id);
      }
      long long int v_sum = lp.second + rp.second;
      long long int need_max = e.cost;
      uf.unionSet(l_id, r_id);
      if (need_max <= v_sum) {
        valid_num += uf.size(l_id);
      }
      ps[uf.root(l_id)] = make_pair(need_max, v_sum);
    } else {
      auto p(ps[l_id]);
      if (p.first <= p.second) {
        valid_num -= uf.size(l_id);
      }
      long long int v_sum = p.second;
      long long int need_max = e.cost;
      if (need_max <= v_sum) {
        valid_num += uf.size(l_id);
      }
      ps[uf.root(l_id)] = make_pair(need_max, v_sum);
    }
    if (valid_num == N) answer = max(answer, i + 1);
  }
  cout << M - answer << endl;
  return 0;
}
