#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<long long>;
using pii = pair<long long, long long>;
const signed INF_ = 1001001001;
const long long INF = 1001001001001001001LL;
const long long DX[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0},
                DY[9] = {-1, 0, 1, 0, -1, 1, 1, -1, 0};
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (auto i = (begin(v)); i != (end(v)); ++i)
    os << *i << (i == end(v) - 1 ? "" : " ");
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto i = (begin(v)); i != (end(v)); ++i) is >> *i;
  return is;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template <class T, class U>
bool chmax(T &a, const U &b) {
  return a < b ? a = b, 1 : 0;
}
template <class T, class U>
bool chmin(T &a, const U &b) {
  return a > b ? a = b, 1 : 0;
}
template <class T>
void PSUM(T &c) {
  partial_sum(begin(c), end(c), begin(c));
}
template <class T>
using heap = priority_queue<T, vector<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(15) << fixed;
  }
} before_main_function;
struct union_find {
  vector<long long> data;
  vector<long long> w;
  union_find(long long size) : data(size, -1), w(size) {}
  void set(long long i, long long x) { w[i] = x; }
  void unite(long long x, long long 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;
      w[x] += w[y];
    }
  }
  long long weight(long long x) {
    x = root(x);
    return w[x];
  }
  bool same(long long x, long long y) { return root(x) == root(y); }
  long long root(long long x) {
    return data[x] < 0 ? x : (data[x] = root(data[x]));
  }
  long long size(long long x) { return -data[root(x)]; }
};
signed main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> X(N);
  cin >> X;
  union_find uf(N + 1);
  for (long long i = 0, ilen = (long long)(N); i < ilen; ++i) uf.set(i, X[i]);
  uf.set(N, 0);
  vector<vi> e(M);
  for (long long i = 0, ilen = (long long)(M); i < ilen; ++i) {
    long long a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    e[i] = {c, a, b};
  }
  sort(begin(e), end(e));
  vector<long long> wlog(M);
  for (long long i = 0, ilen = (long long)(M); i < ilen; ++i) {
    long long a = e[i][1];
    long long b = e[i][2];
    if (!uf.same(a, b)) {
      uf.unite(a, b);
    }
    wlog[i] = uf.weight(a);
  }
  long long ans = 0;
  for (long long i = (long long)(M - 1); i >= 0; --i) {
    long long c = e[i][0];
    long long a = e[i][1];
    long long b = e[i][2];
    if (uf.same(N, a)) {
      continue;
    }
    auto w = wlog[i];
    if (w >= c) {
      uf.unite(N, a);
    } else {
      ans++;
    }
  }
  cout << ans << endl;
  return (0 ^ 0 ^ 0);
}
