#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<long long> X;
vector<pair<int, long long>> g[100010];
class DisjointSet {
 public:
  vector<int> rank;
  vector<pair<int, long long>> p;
  DisjointSet() {}
  DisjointSet(int size) {
    rank.resize(size, 0);
    p.resize(size, make_pair(0, 0));
    for (int i = 0; i < size; i++) makeSet(i);
  }
  void makeSet(int x) {
    p[x] = make_pair(x, X[x]);
    rank[x] = 0;
  }
  bool same(int x, int y) { return findSet(x) == findSet(y); }
  void unite(int x, int y) { link(findSet(x), findSet(y)); }
  void link(int x, int y) {
    if (rank[x] > rank[y]) {
      p[y].first = x;
      p[x].second += p[y].second;
    } else {
      p[x].first = y;
      p[y].second += p[x].second;
      if (rank[x] == rank[y]) {
        rank[y]++;
      }
    }
  }
  int findSet(int x) {
    if (x != p[x].first) {
      p[x].first = findSet(p[x].first);
    }
    return p[x].first;
  }
  long long findSecond(int x) { return p[findSet(x)].second; }
};
vector<pair<long long, pair<int, int>>> edge;
map<pair<int, int>, int> mp;
bool used[100010];
void dfs(int now, long long lim) {
  for (int i = 0; i < g[now].size(); i++) {
    int u = g[now][i].first;
    if (used[u]) continue;
    if (now < u) {
      if (mp[make_pair(now, u)] == 2)
        continue;
      else if (g[now][i].second <= lim) {
        mp[make_pair(now, u)] = 2;
        used[u] = true;
        dfs(u, lim);
      }
    } else {
      if (mp[make_pair(u, now)] == 2)
        continue;
      else if (g[now][i].second <= lim) {
        mp[make_pair(u, now)] = 2;
        used[u] = true;
        dfs(u, lim);
      }
    }
  }
  return;
}
int main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    long long p;
    cin >> p;
    X.push_back(p);
  }
  for (int i = 0; i < M; i++) {
    int a, b, y;
    cin >> a >> b >> y;
    a--;
    b--;
    g[a].push_back(make_pair(b, y));
    g[b].push_back(make_pair(a, y));
    edge.push_back(make_pair(y, make_pair(a, b)));
  }
  DisjointSet us(N + 1);
  sort(edge.begin(), edge.end());
  for (int i = 0; i < M; i++) {
    pair<int, int> tp = edge[i].second;
    if (!us.same(tp.first, tp.second)) us.unite(tp.first, tp.second);
    long long z = us.findSecond(tp.first);
    if (z >= edge[i].first)
      mp[tp] = 1;
    else
      mp[tp] = -1;
  }
  reverse(edge.begin(), edge.end());
  int nans = 0;
  for (int i = 0; i < M; i++) {
    pair<int, int> tp = edge[i].second;
    if (mp[tp] > 1)
      continue;
    else if (mp[tp] == 1) {
      mp[tp] = 2;
      used[tp.first] = true;
      used[tp.second] = true;
      dfs(tp.first, edge[i].first);
      dfs(tp.second, edge[i].first);
    } else
      nans++;
  }
  cout << nans << endl;
  return 0;
}
