#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
struct less_key {
  bool operator()(pair<long long int, long long int> p1,
                  pair<long long int, long long int> p2) {
    return p1.first > p2.first ||
           (p1.first == p2.first && p1.second < p2.second);
  }
};
struct less_key2 {
  bool operator()(pair<long long int, long long int> p1,
                  pair<long long int, long long int> p2) {
    return p1.second > p2.second ||
           (p1.second == p2.second && p1.first > p2.first);
  }
};
const long long int mod = 1000000007ll;
const long long int mod2 = 998244353ll;
const long long int inf = 10000000000000007ll;
const double eps = 1e-10;
template <typename T = long long int, T D = 0>
class MaxOp {
 public:
  static T op(const T& a, const T& b) { return max(a, b); }
  static T def() { return (T)D; }
};
template <typename T = long long int, T D = inf>
class MinOp {
 public:
  static T op(const T& a, const T& b) { return min(a, b); }
  static T def() { return (T)D; }
};
template <typename T = long long int, T D = 0>
class SumOp {
 public:
  static T op(const T& a, const T& b) { return a + b; }
  static T def() { return (T)D; }
};
template <typename D, typename T = long long int>
class SegTree {
 public:
  long long int n;
  vector<T> t;

 private:
  void build(const long long int* a, int v, int tl, int tr) {
    if (tl == tr)
      t[v] = a[tl];
    else {
      int tm = (tl + tr) / 2;
      build(a, v * 2, tl, tm);
      build(a, v * 2 + 1, tm + 1, tr);
      t[v] = D().op(t[v * 2], t[v * 2 + 1]);
    }
  }
  long long int get(int v, int tl, int tr, int l, int r) {
    if (l > r) {
      return D().def();
    }
    if (l == tl && r == tr) {
      return t[v];
    }
    int tm = (tl + tr) / 2;
    return D().op(get(v * 2, tl, tm, l, min(r, tm)),
                  get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
  }
  void update(int v, int tl, int tr, int pos, int new_val) {
    if (tl == tr) {
      t[v] = new_val;
    } else {
      int tm = (tl + tr) / 2;
      if (pos <= tm) {
        update(v * 2, tl, tm, pos, new_val);
      } else {
        update(v * 2 + 1, tm + 1, tr, pos, new_val);
      }
      t[v] = D().op(t[v * 2] + t[v * 2 + 1]);
    }
  }

 public:
  void build(const vector<long long int>& a) {
    n = a.size();
    t.resize(n * 4);
    build(a.data(), 1, 0, n - 1);
  }
  void build(long long int* a, long long int n) {
    this->n = n;
    t.resize(n * 4);
    build(a, 1, 0, n - 1);
  }
  long long int get(long long int l, long long int r) {
    return get(1, 0, n - 1, l, r);
  }
  void update(long long int pos, long long int new_val) {
    update(1, 0, n - 1, pos, new_val);
  }
};
const long long int MAXN = 100005;
long long int parent[MAXN];
void make_set(long long int v) { parent[v] = v; }
long long int find_set(long long int v) {
  if (v == parent[v]) return v;
  return parent[v] = find_set(parent[v]);
}
long long int union_sets(long long int a, long long int b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b) parent[b] = a;
  return a;
}
long long int n, m;
long long int a[MAXN];
long long int vs[MAXN];
long long int vm[MAXN];
bool pr[MAXN];
map<long long int, vector<pair<long long int, long long int>>> e;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.precision(15);
  cout.setf(ios::fixed);
  cin >> n >> m;
  for (long long int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (long long int i = 0; i < m; i++) {
    long long int u, w, y;
    cin >> u >> w >> y;
    e[y].push_back({u, w});
  }
  for (long long int i = 1; i <= n; i++) {
    make_set(i);
  }
  for (long long int i = 1; i <= n; i++) {
    vs[i] = a[i];
    vm[i] = 0;
  }
  long long int R = 0;
  long long int cr = 0;
  long long int cpr = 0;
  for (auto it = e.begin(); it != e.end(); it++) {
    for (auto w : it->second) {
      long long int t1 = find_set(w.first);
      long long int t2 = find_set(w.second);
      if (t1 != t2) {
        long long int t = union_sets(w.first, w.second);
        vs[t] = vs[t1] + vs[t2];
        vm[t] = it->first;
        if (pr[t1]) {
          cpr--;
        }
        pr[t1] = 0;
        if (pr[t2]) {
          cpr--;
        }
        pr[t2] = 0;
        pr[t] = vs[t] < vm[t];
        if (pr[t]) {
          cpr++;
        }
      } else {
        if (pr[t1]) {
          cpr--;
        }
        vm[t1] = it->first;
        pr[t1] = vs[t1] < vm[t1];
        if (pr[t1]) {
          cpr++;
        }
      }
    }
    cr += it->second.size();
    if (cpr == 0) {
      R = cr;
    }
  }
  cout << m - R;
  return 0;
}
