#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
namespace io {
const int L = (1 << 20) + 1;
char buf[L], *S, *T, c;
char getchar() {
  if (__builtin_expect(S == T, 0)) {
    T = (S = buf) + fread(buf, 1, L, stdin);
    return (S == T ? EOF : *S++);
  }
  return *S++;
}
int inp() {
  int x = 0, f = 1;
  char ch;
  for (ch = getchar(); !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); x = x * 10 + ch - '0', ch = getchar())
    ;
  return x * f;
}
unsigned inpu() {
  unsigned x = 0;
  char ch;
  for (ch = getchar(); !isdigit(ch); ch = getchar())
    ;
  for (; isdigit(ch); x = x * 10 + ch - '0', ch = getchar())
    ;
  return x;
}
long long inp_ll() {
  long long x = 0;
  int f = 1;
  char ch;
  for (ch = getchar(); !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); x = x * 10 + ch - '0', ch = getchar())
    ;
  return x * f;
}
char B[25], *outs = B + 20, *outr = B + 20;
template <class T>
inline void print(register T a, register char x = 0) {
  if (x) *--outs = x, x = 0;
  if (!a)
    *--outs = '0';
  else
    while (a) *--outs = (a % 10) + 48, a /= 10;
  if (x) *--outs = x;
  fwrite(outs, outr - outs, 1, stdout);
  outs = outr;
}
};  // namespace io
using io ::inp;
using io ::inp_ll;
using io ::inpu;
using io ::print;
using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
long long power(long long a, long long b, long long p) {
  if (!b) return 1;
  long long t = power(a, b / 2, p);
  t = t * t % p;
  if (b & 1) t = t * a % p;
  return t;
}
const int MAXN = 100010;
const int MAXP = 10000000;
const u64 MOD = 1000000007;
const f80 MI = f80(1) / MOD;
const long long INF = 10000000000000000LL;
const long long inf = 5000000000000LL;
int n, m;
int x[MAXN];
int p[MAXN], tp[MAXN];
int r[MAXN], tr[MAXN];
int ans = 0;
vector<pair<int, int> > v[MAXN], tv[MAXN];
int u[MAXN];
long long limit[MAXN];
void solve(int L, int R) {
  long long sum = 0;
  for (int i = L; i <= R; ++i) {
    sum += x[p[i]];
    u[p[i]] = 0;
  }
  for (int i = L; i <= R; ++i) {
    limit[p[i]] = sum;
    tv[p[i]].clear();
    for (auto e : v[p[i]]) {
      if (e.first <= sum && L <= r[e.second] && r[e.second] <= R)
        tv[p[i]].push_back(e);
    }
    v[p[i]] = tv[p[i]];
  }
  int pos = L;
  vector<int> to;
  for (int i = L; i <= R; ++i) {
    if (!u[p[i]]) {
      queue<int> Q;
      tp[pos] = p[i];
      tr[p[i]] = pos;
      pos++;
      u[p[i]] = 1;
      Q.push(p[i]);
      while (!Q.empty()) {
        int x = Q.front();
        Q.pop();
        for (auto y : v[x])
          if (!u[y.second]) {
            tp[pos] = y.second;
            tr[y.second] = pos;
            pos++;
            u[y.second] = 1;
            Q.push(y.second);
          }
      }
      to.push_back(pos);
    }
  }
  if (to.size() == 1) return;
  for (int i = L; i <= R; ++i) {
    p[i] = tp[i];
    r[i] = tr[i];
  }
  int l = L;
  for (auto r : to) {
    solve(l, r - 1);
    l = r;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &x[i]);
  for (int i = 1; i <= m; ++i) {
    int a, b, y;
    scanf("%d%d%d", &a, &b, &y);
    v[a].emplace_back(y, b);
    v[b].emplace_back(y, a);
  }
  for (int i = 1; i <= n; ++i) sort(v[i].begin(), v[i].end());
  for (int i = 1; i <= n; ++i) p[i] = r[i] = i;
  solve(1, n);
  for (int i = 1; i <= n; ++i) ans += v[i].size();
  cout << m - ans / 2 << endl;
  return 0;
}
