#include <bits/stdc++.h>
using namespace std;
int n, m;
long long x[100010], weight[100010];
int ans[100010], cand[100010];
class Edge {
 public:
  long long cost;
  int from, to, num;
  Edge(long long c, int f, int t, int n) {
    cost = c;
    from = f;
    to = t;
    num = n;
  }
};
vector<Edge> all;
void readGraph(vector<vector<Edge> > &g, int E, bool D, bool C) {
  for (int i = 0; i < E; ++i) {
    Edge e(0, 0, 0, i);
    if (!C)
      cin >> e.from >> e.to;
    else
      cin >> e.from >> e.to >> e.cost;
    g[e.from].push_back(e);
    all.push_back(e);
    if (!D) {
      swap(e.from, e.to);
      g[e.from].push_back(e);
    }
  }
}
bool operator<(const Edge &e, const Edge &f) {
  return e.cost != f.cost   ? e.cost < f.cost
         : e.from != f.from ? e.from < f.from
                            : e.to < f.to;
}
class UnionFind {
 public:
  vector<int> Parent;
  vector<int> Rank;
  UnionFind(int n) {
    ++n;
    Parent.resize(n, 0);
    Rank.resize(n, 0);
    for (int i = 0; i < n; ++i) Parent[i] = i;
  }
  int find(int x) {
    if (Parent[x] == x) return x;
    return Parent[x] = find(Parent[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (Rank[x] < Rank[y]) {
      Parent[x] = y;
      weight[y] += weight[x];
      weight[x] = 0;
    } else {
      Parent[y] = x;
      weight[x] += weight[y];
      weight[y] = 0;
      if (Rank[x] == Rank[y]) ++Rank[x];
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> x[i + 1];
    weight[i + 1] = x[i + 1];
  }
  vector<vector<Edge> > g(n + 1);
  readGraph(g, m, false, true);
  sort(all.begin(), all.end());
  UnionFind uf(n);
  for (int i = 0; i < m; ++i) {
    int a = all[i].from;
    int b = all[i].to;
    a = uf.find(a);
    b = uf.find(b);
    if ((a == b && x[a] >= all[i].cost) ||
        (a != b && weight[a] + weight[b] >= all[i].cost))
      cand[all[i].num] = 1;
    uf.unite(a, b);
  }
  for (int i = m - 1; i >= 0; --i) {
    if (ans[all[i].num] == 1 || cand[all[i].num] == 0) continue;
    ans[all[i].num] = 1;
    queue<int> q;
    q.push(all[i].from);
    q.push(all[i].to);
    while (!q.empty()) {
      int p = q.front();
      q.pop();
      for (int j = 0; j < g[p].size(); ++j) {
        if (ans[g[p][j].num] == 0 && g[p][j].cost <= all[i].cost) {
          ans[g[p][j].num] = 1;
          q.push(g[p][j].to);
        }
      }
    }
  }
  int tmp = 0;
  for (int i = 0; i < m; ++i) tmp += ans[i];
  cout << m - tmp << "\n";
}
