#include <bits/stdc++.h>
using namespace std;
class unionfind {
  int last;
  int *parent, *time;
  std::vector<std::pair<int, size_t>> *size;
  const size_t length;

 public:
  unionfind(size_t n, int *w) : last(0), length(n) {
    parent = new int[n];
    time = new int[n];
    size = new std::vector<std::pair<int, size_t>>[n];
    for (size_t i = 0; i < n; ++i) {
      parent[i] = w[i];
      time[i] = INT32_MAX;
      size[i].emplace_back(0, w[i]);
    }
  }
  size_t root(size_t v, int t) {
    if (time[v] > t)
      return v;
    else
      return root(parent[v], t);
  }
  bool is_same(size_t u, size_t v, int t = -1) {
    if (t < 0) t = last;
    return root(u, t) == root(v, t);
  }
  int merge(size_t u, size_t v) {
    int t = ++last;
    u = root(u, t);
    v = root(v, t);
    if (u == v) return t;
    if (parent[u] < parent[v]) std::swap(u, v);
    parent[u] += parent[v];
    size[u].emplace_back(t, parent[u]);
    parent[v] = u;
    time[v] = t;
    return t;
  }
  size_t count(size_t v, int t = -1) {
    if (t < 0) t = last;
    v = root(v, t);
    return std::prev(std::lower_bound(size[v].begin(), size[v].end(),
                                      std::pair<int, size_t>{t, ~0}))
        ->second;
  }
};
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  static int vw[100000];
  static vector<pair<int, int>> edges[100000];
  static pair<int, pair<int, int>> ew[100000];
  static bool ok[100000];
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> vw[i];
  for (int i = 0; i < m; ++i) {
    int a, b, y;
    cin >> a >> b >> y;
    --a;
    --b;
    edges[a].emplace_back(b, y);
    edges[b].emplace_back(a, y);
    ew[i] = {y, {a, b}};
  }
  sort(ew, ew + m);
  unionfind uf(n, vw);
  for (int i = 0; i < m; ++i) {
    uf.merge(ew[i].second.first, ew[i].second.second);
  }
  int ans = 0;
  for (int t = m; t > 0; --t) {
    int u, v, w;
    w = ew[t - 1].first;
    tie(u, v) = ew[t - 1].second;
    if (ok[u]) continue;
    if (uf.count(u, t + 1) < w)
      ++ans;
    else {
      queue<int> q;
      q.emplace(u);
      q.emplace(v);
      ok[u] = ok[v] = true;
      while (!q.empty()) {
        int f = q.front();
        q.pop();
        for (auto e : edges[f]) {
          if (e.second > w) continue;
          if (ok[e.first]) continue;
          ok[e.first] = true;
          q.emplace(e.first);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
