#include <bits/stdc++.h>
using namespace std;
const long long INF = LLONG_MAX;
const long long MOD = 1e9 + 7;
struct UnionFind {
  vector<long long> data;
  UnionFind(vector<long long> w) : data(w.size(), -1) {
    for (long long i = 0; (i) < (w.size()); ++(i)) {
      data[i] = -w[i];
    }
  }
  bool unionSet(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
};
struct Edge {
  int src, dst;
  long long weight;
  Edge() : src(0), dst(0), weight(0){};
  Edge(int src, int dst, long long weight)
      : src(src), dst(dst), weight(weight) {}
};
bool operator<(const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight < f.weight
         : e.src != f.src     ? e.src < f.src
                              : e.dst < f.dst;
}
int N, M;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> M;
  vector<long long> X(N);
  vector<Edge> E(M);
  vector<vector<pair<int, Edge> > > G(N);
  for (long long i = 0; (i) < (N); ++(i)) {
    cin >> X[i];
  }
  for (long long i = 0; (i) < (M); ++(i)) {
    cin >> E[i].src >> E[i].dst >> E[i].weight;
    E[i].src--;
    E[i].dst--;
  }
  sort(E.begin(), E.end());
  for (long long i = 0; (i) < (M); ++(i)) {
    G[E[i].src].push_back({i, E[i]});
    G[E[i].dst].push_back({i, {E[i].dst, E[i].src, E[i].weight}});
  }
  vector<int> flg(M, 0);
  UnionFind uf(X);
  for (long long i = 0; (i) < (M); ++(i)) {
    uf.unionSet(E[i].src, E[i].dst);
    flg[i] = E[i].weight <= uf.size(E[i].src);
  }
  long long ans = 0;
  for (int i = M - 1; i >= 0; i--) {
    if (flg[i] == 0) ans++;
    if (flg[i] == 1) {
      queue<int> Q;
      Q.push(E[i].src);
      vector<bool> used(N, false);
      while (!Q.empty()) {
        int v = Q.front();
        Q.pop();
        if (used[v]) continue;
        used[v] = true;
        for (auto e : G[v])
          if (e.second.weight <= E[i].weight) {
            flg[e.first] = 2;
            Q.push(e.second.dst);
          }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
