#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wincompatible-pointer-types"
typedef struct {
  int32_t a;
  int32_t b;
} hw;
typedef struct {
  int64_t a;
  int64_t b;
} hwll;
typedef struct {
  int64_t a;
  int64_t b;
  int64_t c;
} hwllc;
typedef struct {
  hwll a;
  hwll b;
} linell;
uint64_t n, m;
uint64_t h, w;
uint64_t k;
uint64_t q;
int64_t va, vb, vc, vd, ve, vf;
uint64_t ua, ub, uc, ud, ue, uf;
long double vra, vrb, vrc;
double vda, vdb, vdc;
char ch, dh;
uint64_t umin(uint64_t x, uint64_t y) { return (x < y) ? x : y; }
uint64_t umax(uint64_t x, uint64_t y) { return (x > y) ? x : y; }
int64_t smin(int64_t x, int64_t y) { return (x < y) ? x : y; }
int64_t smax(int64_t x, int64_t y) { return (x > y) ? x : y; }
uint64_t gcd(uint64_t x, uint64_t y) {
  if (x < y) {
    return gcd(y, x);
  } else if (y == 0) {
    return x;
  } else {
    return gcd(y, x % y);
  }
}
uint64_t bitpow(uint64_t a, uint64_t x, uint64_t modulo) {
  uint64_t result = 1;
  while (x) {
    if (x & 1) {
      result *= a;
      result %= modulo;
    }
    x /= 2;
    a = (a * a) % modulo;
  }
  return result;
}
uint64_t divide(uint64_t a, uint64_t b, uint64_t modulo) {
  return (a * bitpow(b, modulo - 2, modulo)) % modulo;
}
uint64_t udiff(uint64_t a, uint64_t b) {
  if (a >= b) {
    return a - b;
  } else {
    return b - a;
  }
}
int64_t sdiff(int64_t a, int64_t b) {
  if (a >= b) {
    return a - b;
  } else {
    return b - a;
  }
}
int bitcount(uint64_t n) {
  int result = 0;
  while (n) {
    if (n & 1) result++;
    n /= 2;
  }
  return result;
}
int32_t pullcomp(const void *left, const void *right) {
  uint64_t l = *(uint64_t *)left, r = *(uint64_t *)right;
  if ((l) < (r)) return -1;
  if ((l) > (r)) return +1;
  return 0;
}
int32_t prevcomp(const void *left, const void *right) {
  uint64_t l = *(uint64_t *)left, r = *(uint64_t *)right;
  if ((r) < (l)) return -1;
  if ((r) > (l)) return +1;
  return 0;
}
int32_t psllcomp(const void *left, const void *right) {
  int64_t l = *(int64_t *)left, r = *(int64_t *)right;
  if ((l) < (r)) return -1;
  if ((l) > (r)) return +1;
  return 0;
}
int32_t pcharcomp(const void *left, const void *right) {
  char l = *(char *)left, r = *(char *)right;
  if ((l) < (r)) return -1;
  if ((l) > (r)) return +1;
  return 0;
}
int32_t pdoublecomp(const void *left, const void *right) {
  double l = *(double *)left, r = *(double *)right;
  if ((l) < (r)) return -1;
  if ((l) > (r)) return +1;
  return 0;
}
int32_t pstrcomp(const void *left, const void *right) {
  char *l = *(char **)left;
  char *r = *(char **)right;
  return strcmp(l, r);
}
int32_t phwllABcomp(const void *left, const void *right) {
  hwll l = *(hwll *)left, r = *(hwll *)right;
  if ((l.a) < (r.a)) return -1;
  if ((l.a) > (r.a)) return +1;
  if ((l.b) < (r.b)) return -1;
  if ((l.b) > (r.b)) return +1;
  return 0;
}
int32_t phwllREVcomp(const void *left, const void *right) {
  hwll l = *(hwll *)left, r = *(hwll *)right;
  if ((l.b) < (r.b)) return -1;
  if ((l.b) > (r.b)) return +1;
  if ((l.a) < (r.a)) return -1;
  if ((l.a) > (r.a)) return +1;
  return 0;
}
int32_t ptriplecomp(const void *left, const void *right) {
  hwllc l = *(hwllc *)left, r = *(hwllc *)right;
  if ((l.a) < (r.a)) return -1;
  if ((l.a) > (r.a)) return +1;
  if ((l.b) < (r.b)) return -1;
  if ((l.b) > (r.b)) return +1;
  if ((l.c) < (r.c)) return -1;
  if ((l.c) > (r.c)) return +1;
  return 0;
}
int32_t ptripleREVcomp(const void *left, const void *right) {
  hwllc l = *(hwllc *)left, r = *(hwllc *)right;
  if ((l.b) < (r.b)) return -1;
  if ((l.b) > (r.b)) return +1;
  if ((l.a) < (r.a)) return -1;
  if ((l.a) > (r.a)) return +1;
  if ((l.c) < (r.c)) return -1;
  if ((l.c) > (r.c)) return +1;
  return 0;
}
int32_t pquadcomp(const void *left, const void *right) {
  linell l = *(linell *)left;
  linell r = *(linell *)right;
  int64_t ac = phwllABcomp(&(l.a), &(r.a));
  if (ac) return ac;
  int64_t bc = phwllABcomp(&(l.b), &(r.b));
  if (bc) return bc;
  return 0;
}
bool isinrange(int64_t left, int64_t x, int64_t right) {
  return (left <= x && x <= right);
}
bool isinrange_soft(int64_t left, int64_t x, int64_t right) {
  return (left <= x && x <= right) || (left >= x && x >= right);
}
int64_t a[1000000 + 5];
int64_t b[1000000 + 5];
int64_t c[1000000 + 5];
uint64_t d[1000000 + 5];
int64_t e[1000000];
char s[1000000 + 1];
char t[1000000 + 1];
char u[1000000 + 1];
hwll xy[1000000 + 5];
hwllc tup[1000000 + 5];
int64_t table[3005][3005];
uint64_t ming[1000000];
bool isng[1000000];
vector<uint64_t> g[1000000];
void dfs(uint64_t v) {
  for (uint64_t u : g[v]) {
  }
}
uint64_t currt = 0;
uint64_t tim[1000000];
uint64_t parent[1000000];
uint64_t size[1000000];
uint64_t cost[1000000];
vector<pair<uint64_t, uint64_t> > costhist[1000000];
uint64_t find(uint64_t t, uint64_t v) {
  if (t < tim[v]) return v;
  return find(t, parent[v]);
}
bool unite(uint64_t v, uint64_t u) {
  v = find(currt, v);
  u = find(currt, u);
  if (v == u) return false;
  ++currt;
  if (size[v] < size[u]) {
    v ^= u;
    u ^= v;
    v ^= u;
  }
  size[v] += size[u];
  cost[v] += cost[u];
  costhist[v].push_back(pair<uint64_t, uint64_t>(currt, cost[v]));
  parent[u] = v;
  tim[u] = currt;
  return true;
}
pair<uint64_t, uint64_t> costview(uint64_t t, uint64_t v) {
  v = find(t, v);
  int64_t ok = 0, ng = costhist[v].size();
  while (ok + 1 < ng) {
    int64_t med = (ok + ng) / 2;
    if (t >= costhist[v][med].first) {
      ok = med;
    } else {
      ng = med;
    }
  }
  return costhist[v][ok];
}
uint64_t p[1000000], ss[1000000], cc[1000000];
uint64_t f(uint64_t x) {
  if (p[x] == x) return x;
  return p[x] = f(p[x]);
}
void un(uint64_t a, uint64_t b) {
  a = f(a);
  b = f(b);
  if (a == b) return;
  if (ss[a] < ss[b]) {
    a ^= b;
    b ^= a;
    a ^= b;
  }
  ss[a] += ss[b];
  cc[a] += cc[b];
  p[b] = a;
}
uint64_t solve() {
  int64_t i, j, ki, li;
  int64_t result = 0;
  double dresult = 0;
  int64_t maybe = 0;
  int64_t sum = 0;
  int64_t item;
  uint64_t *dpcell;
  priority_queue<pair<uint64_t, uint64_t>, vector<pair<uint64_t, uint64_t> >,
                 greater<pair<uint64_t, uint64_t> > >
      que;
  for (i = 0; i < n; i++) {
    tim[i] = 2000000000000007LL;
    parent[i] = i;
    size[i] = 1;
    cost[i] = d[i];
    costhist[i].push_back(pair<uint64_t, uint64_t>(0, d[i]));
  }
  for (i = 0; i < m; i++) {
    que.push(pair<uint64_t, uint64_t>(c[i], i));
  }
  while (!que.empty()) {
    uint64_t v = que.top().second;
    que.pop();
    if (find(currt, a[v]) == find(currt, b[v])) continue;
    ming[currt] = v;
    unite(a[v], b[v]);
  }
  queue<uint64_t> que2;
  que2.push(n - 1);
  while (!que2.empty()) {
    uint64_t t = que2.front();
    uint64_t e = ming[t];
    que2.pop();
    if (t == 0) continue;
    if (costview(t, a[e]).second < c[e]) {
      isng[t] = true;
      que2.push(costview(t - 1, a[e]).first);
      que2.push(costview(t - 1, b[e]).first);
    }
  }
  for (i = 0; i < n; i++) {
    p[i] = i;
    ss[i] = 1;
    cc[i] = d[i];
  }
  for (i = 0; i < n - 1; i++) {
    if (!isng[i]) {
      un(a[ming[i]], b[ming[i]]);
    }
  }
  for (i = 0; i < m; i++) {
    if (f(a[i]) == f(b[i]) && cc[f(a[i])] >= c[i]) {
      result++;
    }
  }
  printf("%lld\n", result);
  return 0;
success:
  puts("Yes");
  return 0;
fail:
  puts("0");
  return 1;
}
int32_t main(void) {
  int32_t i, j;
  int32_t x, y;
  n = 3;
  scanf("%llu%llu", &n, &m);
  for (i = 0; i < n; i++) {
    scanf("%llu", &d[i]);
  }
  for (i = 0; i < m; i++) {
    scanf("%lld", &a[i]);
    scanf("%lld", &b[i]);
    scanf("%lld", &c[i]);
    a[i]--;
    b[i]--;
  }
  solve();
  return 0;
}
