#include <bits/stdc++.h>
using namespace std;
long long n, m, par[100005], first[100005], cost, vis[100005], entry[100005],
    ext[100005], tim = 1, s[100005], ans, d[100005];
vector<pair<long long, long long>> a[100005];
vector<long long> adj[100005];
vector<pair<long long, pair<long long, long long>>> edges;
set<pair<long long, pair<long long, long long>>> taken;
long long fp(long long w) {
  if (par[w] == w)
    return w;
  else
    return par[w] = fp(par[w]);
}
void merge(long long u, long long v) {
  u = fp(u);
  v = fp(v);
  par[u] = v;
}
void dfs(long long node) {
  entry[node] = tim++;
  vis[node] = 1;
  s[node] = first[node];
  for (auto i : adj[node]) {
    if (!vis[i]) {
      d[i] = d[node] + 1;
      dfs(i);
      s[node] += s[i];
    }
  }
  ext[node] = tim - 1;
}
const long long N = 100005;
long long seg[4 * N], lazy[4 * N];
void build(long long node, long long start, long long end) {
  if (start == end) {
    seg[node] = 1;
    return;
  }
  long long mid = (start + end) >> 1;
  build(node << 1, start, mid);
  build(node << 1 | 1, mid + 1, end);
  seg[node] = seg[node << 1] + seg[node << 1 | 1];
}
void update(long long node, long long start, long long end, long long l,
            long long r, long long val) {
  if (lazy[node] != 0) {
    seg[node] = lazy[node];
    if (start != end) {
      lazy[node << 1] = lazy[node];
      lazy[node << 1 | 1] = lazy[node];
    }
    lazy[node] = 0;
  }
  if (start > end || start > r || end < l) return;
  if (l <= start && end <= r) {
    seg[node] = val;
    if (start != end) {
      lazy[node << 1] = val;
      lazy[node << 1 | 1] = val;
    }
    return;
  }
  long long mid = (start + end) >> 1;
  update(node << 1, start, mid, l, r, val);
  update(node << 1 | 1, mid + 1, end, l, r, val);
  seg[node] = seg[node << 1] + seg[node << 1 | 1];
}
long long query(long long node, long long start, long long end, long long l,
                long long r) {
  if (start > end || start > r || end < l) return 0;
  if (lazy[node] != 0) {
    seg[node] = lazy[node];
    if (start != end) {
      lazy[node << 1] = lazy[node];
      lazy[node << 1 | 1] = lazy[node];
    }
    lazy[node] = 0;
  }
  if (start >= l && end <= r) return seg[node];
  long long mid = (start + end) >> 1;
  long long q1 = query(node << 1, start, mid, l, r);
  long long q2 = query(node << 1 | 1, mid + 1, end, l, r);
  return q1 + q2;
}
long long seg2[N << 2];
long long query2(long long node, long long start, long long end, long long l,
                 long long r) {
  if (l <= start && r >= end) return seg2[node];
  if (r < start || l > end || l > r) return 0;
  long long mid = (start + end) >> 1;
  long long ans1 = query2(node << 1, start, mid, l, r);
  long long ans2 = query2(node << 1 | 1, mid + 1, end, l, r);
  return (ans1 + ans2);
}
void update2(long long node, long long start, long long end, long long pos,
             long long val) {
  if (start == end) {
    seg2[node] += val;
    return;
  }
  long long mid = (start + end) >> 1;
  if (start <= pos && pos <= mid)
    update2(node << 1, start, mid, pos, val);
  else
    update2(node << 1 | 1, mid + 1, end, pos, val);
  seg2[node] = seg2[node << 1] + seg2[node << 1 | 1];
}
void solve() {
  cin >> n >> m;
  for (long long i = 1; i < n + 1; i++) cin >> first[i], par[i] = i;
  for (long long i = 0; i < m; i++) {
    long long u, v, w;
    cin >> u >> v >> w;
    a[u].push_back({v, w});
    a[v].push_back({u, w});
    edges.push_back({w, {u, v}});
  }
  sort((edges).begin(), (edges).end());
  for (auto i : edges) {
    if (fp(i.second.first) == fp(i.second.second)) continue;
    merge(i.second.first, i.second.second);
    taken.insert(i);
    adj[i.second.first].push_back(i.second.second);
    adj[i.second.second].push_back(i.second.first);
    cost = i.first;
  }
  dfs(1);
  build(1, 1, n);
  reverse((edges).begin(), (edges).end());
  for (auto i : edges) {
    long long g = query(1, 1, n, entry[i.second.first], entry[i.second.first]);
    long long val = s[g] - query2(1, 1, n, entry[g] + 1, ext[g]);
    if (i.first > val) {
      ans++;
      if (taken.count(i) == 0) continue;
      long long u = i.second.first, v = i.second.second;
      if (d[u] > d[v]) swap(u, v);
      update(1, 1, n, entry[v], ext[v], v);
      update2(1, 1, n, entry[v], s[v]);
    }
  }
  cout << ans << '\n';
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
