#include <bits/stdc++.h>
using namespace std;
int N, M;
long long xs[100000 + 10];
struct E {
  int a, b;
  long long c;
  E() {}
  E(int a, int b, long long c) : a(a), b(b), c(c) {}
};
bool operator<(const E& e1, const E& e2) { return e1.c < e2.c; }
E es[100000 + 10];
struct D {
  int t;
  int d;
  long long s;
  D() {}
  D(int t, int d, long long s) : t(t), d(d), s(s) {}
};
bool operator<(const D& d1, const D& d2) { return d1.t < d2.t; }
vector<D> data[100000 + 5];
;
void init(int n) {
  for (int i = 0; i < (int)(n); ++i) {
    data[i].push_back(D(-1, -1, xs[i]));
  }
}
int rootOf(int a, int t) {
  D d = data[a].back();
  if (d.d >= 0) {
    int r = rootOf(d.d, t);
    data[a].push_back(D(t, d.d, d.s));
    return r;
  } else {
    return a;
  }
}
long long vsum(int a, int t) {
  for (;;) {
    while (data[a].back().t >= t) {
      data[a].pop_back();
    }
    const D& d = data[a].back();
    if (d.d < 0) {
      return d.s;
    }
    a = d.d;
  }
  assert(false);
}
bool unify(int a, int b, int t) {
  int ra = rootOf(a, t), rb = rootOf(b, t);
  if (ra == rb) return false;
  if (data[ra].back().d < data[ra].back().d) swap(ra, rb);
  data[rb].push_back(D(t, data[rb].back().d + data[ra].back().d,
                       data[rb].back().s + data[ra].back().s));
  data[ra].push_back(D(t, rb, data[rb].back().s + data[ra].back().s));
  return true;
}
vector<E> g[100000 + 10];
bool marked[100000 + 10];
void mark(int u, int c) {
  if (marked[u]) {
    return;
  }
  marked[u] = true;
  for (const E& e : g[u]) {
    if (e.c <= c) {
      mark(e.b, c);
    }
  }
}
int main(void) {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < (int)(N); ++i) {
    scanf("%lld", &xs[i]);
  }
  for (int i = 0; i < (int)(M); ++i) {
    int a, b;
    long long c;
    scanf("%d%d%lld", &a, &b, &c);
    --a;
    --b;
    es[i] = E(a, b, c);
    g[a].push_back(E(a, b, c));
    g[b].push_back(E(b, a, c));
  }
  sort(es, es + M);
  init(N);
  for (int t = 0; t < (int)(M); ++t) {
    unify(es[t].a, es[t].b, t);
  }
  int res = 0;
  for (int t = M - 1; t >= 0; --t) {
    const E& e = es[t];
    assert(marked[e.a] == marked[e.b]);
    if (marked[e.a]) {
      continue;
    }
    long long sum = vsum(e.a, t + 1);
    if (sum >= e.c) {
      mark(e.a, e.c);
    } else {
      ++res;
    }
  }
  cout << res << endl;
  return 0;
}
