#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using graph = vector<set<int>>;
class union_find {
  vector<int> par;
  int find(int a) { return par[a] < 0 ? a : par[a] = find(par[a]); }

 public:
  union_find(int n) : par(n, -1) {}
  bool same(int a, int b) { return find(a) == find(b); }
  void unite(int a, int b) {
    a = find(a);
    b = find(b);
    if (a == b) return;
    if (par[a] < par[b]) {
      par[a] += par[b];
      par[b] = a;
    } else {
      par[b] += par[a];
      par[a] = b;
    }
  }
  int size(int a) { return -par[find(a)]; }
};
class lct_node {
  lct_node *l, *r, *p;
  bool rev;
  int pos() {
    if (p && p->l == this) return 1;
    if (p && p->r == this) return 3;
    return 0;
  }
  void push() {
    if (pos()) p->push();
    if (rev) {
      swap(l, r);
      if (l) l->rev ^= true;
      if (r) r->rev ^= true;
      rev = false;
    }
  }
  void rot() {
    lct_node *par = p;
    lct_node *mid;
    if (p->l == this) {
      mid = r;
      r = par;
      par->l = mid;
    } else {
      mid = l;
      l = par;
      par->r = mid;
    }
    if (mid) mid->p = par;
    p = par->p;
    par->p = this;
    if (p && p->l == par) p->l = this;
    if (p && p->r == par) p->r = this;
  }
  void splay() {
    push();
    while (pos()) {
      int st = pos() ^ p->pos();
      if (!st)
        p->rot(), rot();
      else if (st == 2)
        rot(), rot();
      else
        rot();
    }
  }

 public:
  lct_node() : l(nullptr), r(nullptr), p(nullptr), rev(false) {}
  void expose() {
    for (lct_node *x = this, *y = nullptr; x; y = x, x = x->p)
      x->splay(), x->r = y;
    splay();
  }
  void evert() {
    expose();
    rev = true;
  }
  void link(lct_node *x) {
    evert();
    p = x;
  }
  void cut() {
    expose();
    l->p = nullptr;
    l = nullptr;
  }
  lct_node *root() {
    expose();
    lct_node *t = this;
    while (t->l) t = t->l;
    t->expose();
    return t;
  }
  lct_node *lca(lct_node *x) {
    x->expose();
    expose();
    bool same = false;
    lct_node *res = x;
    while (x) {
      if (x->p && !x->pos()) res = x->p;
      if (x == this) same = true;
      x = x->p;
    }
    return same ? res : nullptr;
  }
};
unsigned xor128() {
  static unsigned x = 123456789, y = 362436069, z = 521288629, w = 88675123;
  unsigned t = x ^ (x << 11);
  x = y;
  y = z;
  z = w;
  return w = w ^ (w >> 19) ^ (t ^ (t >> 8));
}
const int MAX = 1e5;
lct_node lct[MAX];
int main() {
  int N, M;
  cin >> N >> M;
  vector<ll> X(N);
  for (int i = 0; i < N; i++) {
    cin >> X[i];
  }
  vector<tuple<int, int, int>> tps;
  for (int i = 0; i < M; i++) {
    int A, B, Y;
    cin >> A >> B >> Y;
    --A, --B;
    tps.emplace_back(Y, A, B);
  }
  sort(tps.begin(), tps.end());
  ll all = accumulate(X.begin(), X.end(), 0LL);
  int res = 0;
  vector<tuple<int, int, int>> tes, oth;
  union_find uf(N);
  graph G(N);
  for (auto tp : tps) {
    int A, B, Y;
    tie(Y, A, B) = tp;
    if (!uf.same(A, B)) {
      uf.unite(A, B);
      if (Y > all) {
        ++res;
        continue;
      }
      tes.emplace_back(Y, A, B);
      lct[A].link(lct + B);
      G[A].insert(B);
      G[B].insert(A);
    } else {
      oth.emplace_back(Y, A, B);
    }
  }
  function<ll(int, int)> calc = [&](int v, int prev) {
    ll sum = X[v];
    for (auto to : G[v])
      if (to != prev) {
        sum += calc(to, v);
      }
    return sum;
  };
  vector<ll> sum(N);
  function<void(int, int, ll)> paste = [&](int v, int prev, ll val) {
    sum[v] = val;
    for (auto to : G[v])
      if (to != prev) {
        paste(to, v, val);
      }
  };
  for (int i = 0; i < N; i++)
    if (!sum[i]) {
      paste(i, -1, calc(i, -1));
    }
  reverse(tes.begin(), tes.end());
  for (auto tp : tes) {
    int Y, A, B;
    tie(Y, A, B) = tp;
    int v = lct[A].root() - lct;
    if (sum[v] < Y) {
      ++res;
      sum[A] = sum[v];
      lct[A].evert();
      lct[B].cut();
      G[A].erase(B);
      G[B].erase(A);
      ll aa = sum[v], bb = aa - calc(A, -1);
      sum[A] = aa - bb;
      sum[lct[B].root() - lct] = bb;
    }
  }
  for (auto tp : oth) {
    int Y, A, B;
    tie(Y, A, B) = tp;
    int a = lct[A].root() - lct;
    int b = lct[B].root() - lct;
    if (a != b || sum[a] < Y) {
      ++res;
    }
  }
  cout << res << endl;
  return 0;
}
