#include <bits/stdc++.h>
using namespace std;
using vi = vector<long long>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vp = vector<pair<long long, long long> >;
using vvp = vector<vp>;
using vb = vector<bool>;
using vvb = vector<vb>;
const long long inf = 1001001001001001001;
const int INF = 1001001001;
const int mod = 1000000007;
const double eps = 1e-10;
template <class T>
bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
void out(T a) {
  cout << a << '\n';
}
template <class T>
void outp(T a) {
  cout << '(' << a.first << ',' << a.second << ')' << '\n';
}
template <class T>
void outvp(T v) {
  for (long long i = 0; i < (long long)(v.size()); i++)
    cout << '(' << v[i].first << ',' << v[i].second << ')';
  cout << '\n';
}
template <class T>
void outvvp(T v) {
  for (long long i = 0; i < (long long)(v.size()); i++) outvp(v[i]);
}
template <class T>
void outv(T v) {
  for (long long i = 0; i < (long long)(v.size()); i++) {
    if (i) cout << ' ';
    cout << v[i];
  }
  cout << '\n';
}
template <class T>
void outvv(T v) {
  for (long long i = 0; i < (long long)(v.size()); i++) outv(v[i]);
}
template <class T>
bool isin(T x, T l, T r) {
  return (l) <= (x) && (x) <= (r);
}
template <class T>
void yesno(T b) {
  if (b)
    out("yes");
  else
    out("no");
}
template <class T>
void YesNo(T b) {
  if (b)
    out("Yes");
  else
    out("No");
}
template <class T>
void YESNO(T b) {
  if (b)
    out("YES");
  else
    out("NO");
}
template <class T>
void noyes(T b) {
  if (b)
    out("no");
  else
    out("yes");
}
template <class T>
void NoYes(T b) {
  if (b)
    out("No");
  else
    out("Yes");
}
template <class T>
void NOYES(T b) {
  if (b)
    out("NO");
  else
    out("YES");
}
void outs(long long a, long long b) {
  if (a >= inf - 100)
    out(b);
  else
    out(a);
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long modpow(long long a, long long b) {
  a %= mod;
  if (b == 0) return 1;
  if (b & 1) return a * modpow(a, b - 1) % mod;
  long long k = modpow(a, b / 2);
  return k * k % mod;
}
vi parent, rankk, sz, v;
void init(long long n) {
  parent = vi(n);
  rankk = vi(n);
  sz = v;
  for (long long i = 0; i < (long long)(n); i++) parent[i] = i;
}
long long root(long long i) {
  if (parent[i] == i) return i;
  return root(parent[i]);
}
long long getsize(long long i) { return sz[root(i)]; }
bool same(long long a, long long b) { return root(a) == root(b); }
bool heigou(long long x, long long y) {
  x = root(x);
  y = root(y);
  if (x == y) return false;
  if (rankk[x] < rankk[y]) {
    parent[x] = y;
    sz[y] += sz[x];
  } else {
    parent[y] = x;
    sz[x] += sz[y];
  }
  if (rankk[x] == rankk[y]) rankk[x]++;
  return true;
}
int main() {
  long long n, m;
  cin >> n >> m;
  vp s(m), hen(m), e(m);
  v = vi(n);
  vvp g(n);
  for (long long i = 0; i < (long long)(n); i++) cin >> v[i];
  init(n);
  for (long long i = 0; i < (long long)(m); i++) {
    cin >> hen[i].first >> hen[i].second >> e[i].first;
    hen[i].first--;
    hen[i].second--;
    g[hen[i].first].emplace_back(hen[i].second, i);
    g[hen[i].second].emplace_back(hen[i].first, i);
  }
  for (long long i = 0; i < (long long)(m); i++) e[i].second = i;
  sort(e.begin(), e.end());
  for (long long i = 0; i < (long long)(m); i++) {
    int w = e[i].second;
    if (same(hen[w].first, hen[w].second))
      s[w] = pair<long long, long long>(getsize(hen[w].first), 0);
    else {
      s[w] = pair<long long, long long>(getsize(hen[w].first),
                                        getsize(hen[w].second));
      heigou(hen[w].first, hen[w].second);
    }
  }
  vb use(m, false), del(m, false);
  reverse(e.begin(), e.end());
  for (long long i = 0; i < (long long)(m); i++) {
    int w = e[i].second, a = hen[w].first, b = hen[w].second;
    if (use[w]) continue;
    if (s[w].first + s[w].second >= e[i].first) {
      queue<int> q;
      use[w] = true;
      q.push(a);
      q.push(b);
      while (!q.empty()) {
        auto t = q.front();
        q.pop();
        for (auto x : g[t]) {
          if (!use[x.second]) {
            use[x.second] = true;
            q.push(x.first);
          }
        }
      }
    } else
      del[w] = true;
  }
  long long ans = 0;
  for (long long i = 0; i < (long long)(m); i++)
    if (del[i]) ans++;
  out(ans);
}
