#include <bits/stdc++.h>
using namespace std;
template <class A>
void pr(A a) {
  cout << a;
  cout << '\n';
}
template <class A, class B>
void pr(A a, B b) {
  cout << a << ' ';
  pr(b);
}
template <class A, class B, class C>
void pr(A a, B b, C c) {
  cout << a << ' ';
  pr(b, c);
}
template <class A, class B, class C, class D>
void pr(A a, B b, C c, D d) {
  cout << a << ' ';
  pr(b, c, d);
}
template <class A>
void PR(A a, long long n) {
  for (long long i = (long long)(0); i < (long long)(n); i++) {
    if (i) cout << ' ';
    cout << a[i];
  }
  cout << '\n';
}
long long check(long long n, long long m, long long x, long long y) {
  return x >= 0 && x < n && y >= 0 && y < m;
}
const long long MAX = 1e9 + 7, MAXL = 1LL << 61, dx[4] = {-1, 0, 1, 0},
                dy[4] = {0, 1, 0, -1};
long long p[100001], r[100001], c[100001], d[100001], e[100001];
void init() {
  for (long long i = (long long)(0); i < (long long)(100001); i++)
    p[i] = i, r[i] = 0, d[i] = 0, e[i] = 0;
}
int find(int x) { return (p[x] == x) ? x : (p[x] = find(p[x])); }
void unite(int x, int y) {
  x = find(x), y = find(y);
  if (x == y) return;
  int cx = c[x], cy = c[y];
  if (r[x] < r[y])
    p[x] = y;
  else {
    p[y] = x;
    if (r[x] == r[y]) r[x]++;
  }
  c[find(x)] = cx + cy;
}
bool same(int x, int y) { return find(x) == find(y); }
void Main() {
  init();
  long long n, m;
  cin >> n >> m;
  for (long long i = (long long)(0); i < (long long)(n); i++) cin >> c[i];
  vector<pair<long long, long long> > v[n];
  pair<long long, pair<long long, long long> > p[m];
  for (long long i = (long long)(0); i < (long long)(m); i++) {
    long long x, y, z;
    cin >> x >> y >> z;
    x--, y--;
    v[x].push_back(pair<long long, long long>(y, z));
    v[y].push_back(pair<long long, long long>(x, z));
    p[i] = pair<long long, pair<long long, long long> >(
        z, pair<long long, long long>(x, y));
  }
  sort(p, p + m);
  int u[m], cnt = 0, k = -1;
  memset(u, 0, sizeof(u));
  for (long long i = (long long)(0); i < (long long)(m); i++) {
    long long x = p[i].second.first, y = p[i].second.second, z = p[i].first;
    if (same(x, y)) {
      if (c[find(x)] >= z) {
        d[find(x)] = z;
        u[i] = 1;
      }
      continue;
    }
    long long e1 = e[find(x)], e2 = e[find(y)];
    long long xx = d[find(x)], yy = d[find(y)];
    unite(x, y);
    d[find(x)] = z;
    if (c[find(x)] < d[find(x)]) {
      e[find(x)] = 1;
      cnt++;
      cnt -= e1 + e2;
    } else {
      e[find(x)] = 0;
      cnt -= e1 + e2;
    }
    if (!cnt) k = i;
  }
  init();
  for (long long i = (long long)(0); i < (long long)(k + 1); i++) {
    long long x = p[i].second.first, y = p[i].second.second, z = p[i].first;
    if (same(x, y)) {
      if (c[find(x)] >= z) {
        d[find(x)] = z;
        u[i] = 1;
      }
      continue;
    }
    long long xx = d[find(x)], yy = d[find(y)];
    unite(x, y);
    d[find(x)] = z;
    u[i] = 1;
  }
  long long ans = 0;
  for (long long i = (long long)(0); i < (long long)(m); i++) ans += !u[i];
  pr(ans);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  Main();
  return 0;
}
