#include <bits/stdc++.h>
using namespace std;
using Complex = complex<double>;
using ll = long long;
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
class UnionFind {
 public:
  vector<ll> s, p;
  UnionFind(int size) {
    s.resize(size, 0);
    p.resize(size, 0);
    for (int i = 0; i < size; i++) makeSet(i);
  }
  void makeSet(int x) {
    p[x] = x;
    s[x] = 1;
  }
  void setcost(int x, ll cost) { s[x] = cost; }
  bool same(int x, int y) { return findSet(x) == findSet(y); }
  void unite(int x, int y) {
    x = findSet(x);
    y = findSet(y);
    if (x == y) return;
    if (s[x] < s[y]) swap(x, y);
    p[y] = x;
    s[x] += s[y];
  }
  int findSet(int x) {
    if (x == p[x]) return p[x];
    return p[x] = findSet(p[x]);
  }
  int getsize(int x) { return s[findSet(x)]; }
};
vector<vector<ll>> E;
vector<pair<int, ll>> Eli[101010];
map<pair<int, int>, int> mpE;
int fl[101010];
int used[101010];
void dfs(int now, ll cost) {
  for (auto &x : Eli[now]) {
    int to = x.first;
    ll c = x.second;
    int idx = mpE[{min(now, to), max(now, to)}];
    if (c <= cost) {
      if (!used[idx]) {
        used[idx] = 1;
        dfs(to, cost);
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  UnionFind un = UnionFind(N);
  for (int i = 0; i < N; i++) {
    ll X;
    cin >> X;
    un.setcost(i, X);
  }
  for (int i = 0; i < M; i++) {
    int A, B, X;
    cin >> A >> B >> X;
    A--, B--;
    E.push_back({X, A, B});
    Eli[A].push_back({B, X});
    Eli[B].push_back({A, X});
  }
  sort((E).begin(), (E).end());
  queue<vector<ll>> q;
  for (int i = 0; i < M; i++) {
    ll X = E[i][0];
    int A = E[i][1];
    int B = E[i][2];
    mpE[{min(A, B), max(A, B)}] = i;
    ll S;
    while (q.size() && q.front()[0] < X) {
      S = un.getsize(q.front()[1]);
      fl[q.front()[3]] = (S >= q.front()[0]);
      q.pop();
    }
    un.unite(A, B);
    q.push({X, A, B, i});
  }
  while (q.size()) {
    ll S = un.getsize(q.front()[1]);
    fl[q.front()[3]] = (S >= q.front()[0]);
    q.pop();
  }
  for (int i = M - 1; i >= 0; i--) {
    ll X = E[i][0];
    int A = E[i][1];
    int B = E[i][2];
    if (fl[i] != 1) continue;
    used[i] = 1;
    dfs(A, X);
    dfs(B, X);
  }
  int ans = M;
  for (int i = 0; i < M; i++) ans -= (fl[i] || used[i]);
  cout << ans << endl;
  return 0;
}
