#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
typedef struct data {
  long long u, v, w, idx;
  data() {}
  data(long long u, long long v, long long w, long long idx)
      : u(u), v(v), w(w), idx(idx) {}
} edge;
long long n, m;
long long connected;
long long root[N], sz[N], x[N], sum[N];
vector<pair<long long, long long> > g[N];
data edges[N];
void init() {
  for (long long i = 1; i <= n; i++) {
    root[i] = i;
    sz[i] = 1;
    sum[i] = x[i];
  }
  connected = n;
}
long long rt(long long k) {
  while (k != root[k]) {
    root[k] = root[root[k]];
    k = root[k];
  }
  return k;
}
void merge(long long u, long long v) {
  long long rt1 = rt(u);
  long long rt2 = rt(v);
  if (rt1 == rt2) return;
  connected--;
  if (sz[rt1] > sz[rt2]) swap(rt1, rt2);
  sz[rt2] += sz[rt1];
  sz[rt1] = 0;
  root[rt1] = root[rt2];
  sum[rt2] += sum[rt1];
}
void add_edge(long long idx, long long u, long long v, long long w) {
  g[u].push_back({v, w});
  g[v].push_back({u, w});
  edges[idx] = edge(u, v, w, idx);
}
bool comp(data &d1, data &d2) { return d1.w < d2.w; }
bool kruskalMST(long long lim) {
  init();
  long long cost = 0;
  sort(edges + 1, edges + m + 1, comp);
  for (long long i = 1; i <= lim; i++) {
    long long u = edges[i].u, v = edges[i].v, w = edges[i].w;
    long long rt1 = rt(u), rt2 = rt(v);
    if (rt1 == rt2)
      continue;
    else
      merge(rt1, rt2);
  }
  for (long long i = 1; i <= lim; i++) {
    long long w = edges[i].w;
    long long rt1 = rt(edges[i].u);
    if (sum[rt1] < w) return 0;
  }
  return 1;
}
long long check(long long x) { return kruskalMST(m - x); }
long long binsearch(long long lo, long long hi) {
  while (lo < hi) {
    long long mid = (lo + hi) / 2;
    if (check(mid))
      hi = mid;
    else
      lo = mid + 1;
  }
  return lo;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) cin >> x[i];
  init();
  for (long long i = 1; i <= m; i++) {
    long long u, v, w;
    cin >> u >> v >> w;
    add_edge(i, u, v, w);
  }
  long long ans = binsearch(0, m);
  cout << ans;
  return 0;
}
