#include <bits/stdc++.h>
using namespace std;
template <class T>
using VV = vector<vector<T>>;
template <class T>
inline T SMIN(T& a, const T b) {
  return a = (a > b) ? b : a;
}
template <class T>
inline T SMAX(T& a, const T b) {
  return a = (a < b) ? b : a;
}
template <class Iter>
void __kumaerrc(Iter begin, Iter end) {
  for (; begin != end; ++begin) {
    cerr << *begin << ',';
  }
  cerr << endl;
}
void __kumaerr(istream_iterator<string> it) {
  (void)it;
  cerr << endl;
}
template <typename T, typename... Args>
void __kumaerr(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << "=" << a << ", ", __kumaerr(++it, args...);
}
template <typename S, typename T>
std::ostream& operator<<(std::ostream& _os, const std::pair<S, T>& _p) {
  return _os << "{" << _p.first << ',' << _p.second << "}";
}
const int MAX_N = 1e6 + 1;
vector<pair<long long, int>> G[MAX_N];
tuple<long long, int, int> E[MAX_N];
long long X[MAX_N];
int N, M;
struct UF {
 public:
  int N, G;
  vector<long long> maxY, sumX;
  vector<int> cntE;
  UF(int N) : N(N) { init(N); }
  void init(int N) {
    par = vector<int>(N), rank = vector<int>(N), cnt = vector<int>(N, 1),
    maxY = vector<long long>(N, 0), sumX = vector<long long>(N, 0),
    cntE = vector<int>(N, 0);
    for (int i = 0; i < N; ++i)
      par[i] = i, rank[i] = 0, cnt[i] = 1, sumX[i] = X[i], cntE[i] = 0;
    G = N;
  }
  int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); }
  int count(int x) { return cnt[find(x)]; }
  bool sameset(int x, int y) { return find(x) == find(y); }
  int unite(int x, int y, long long w) {
    x = find(x), y = find(y);
    if (x == y) {
      SMAX(maxY[x], w);
      cntE[x]++;
      return x;
    }
    G--, cnt[x] = cnt[y] = cnt[x] + cnt[y];
    int p = x, c = y;
    if (rank[p] > rank[c])
      swap(p, c);
    else
      rank[p] += rank[p] == rank[c];
    par[c] = p;
    sumX[p] += sumX[c], maxY[p] = max(maxY[c], w), cntE[p] += cntE[c] + 1;
    return p;
  }
  bool ok(int u) {
    int p = find(u);
    return sumX[p] >= maxY[p];
  }

 private:
  vector<int> par, rank, cnt;
};
void bruteforce() {
  int res = MAX_N, rmask = -1;
  for (int mask = 0; mask < (1 << M); ++mask) {
    for (int i = 0; i < (N); ++i) G[i].clear();
    UF uf(N);
    for (int i = 0; i < (M); ++i)
      if ((mask >> i) & 1) {
        long long y;
        int u, v;
        tie(y, u, v) = E[i];
        G[u].emplace_back(y, v);
        G[v].emplace_back(y, u);
        if (mask == 2) {
          string _s = "u, v";
          replace(_s.begin(), _s.end(), ',', ' ');
          stringstream _ss(_s);
          istream_iterator<string> _it(_ss);
          __kumaerr(_it, u, v);
        };
      }
    map<int, long long> xsum;
    for (int i = 0; i < (N); ++i) xsum[uf.find(i)] += X[i];
    bool ok = true;
    for (int i = 0; i < (M); ++i)
      if ((mask >> i) & 1) {
        long long y;
        int u, v;
        tie(y, u, v) = E[i];
        ok &= (xsum[uf.find(u)] >= y);
        if (mask == 15) {
          string _s =
              "mask, i, u, v, xsum[uf.find(u)], y, xsum[uf.find(u)] >= y";
          replace(_s.begin(), _s.end(), ',', ' ');
          stringstream _ss(_s);
          istream_iterator<string> _it(_ss);
          __kumaerr(_it, mask, i, u, v, xsum[uf.find(u)], y,
                    xsum[uf.find(u)] >= y);
        };
      }
    if (mask == 15) {
      {
        string _s = "mask, ok";
        replace(_s.begin(), _s.end(), ',', ' ');
        stringstream _ss(_s);
        istream_iterator<string> _it(_ss);
        __kumaerr(_it, mask, ok);
      };
    }
    if (ok && M - __builtin_popcount(mask) < res)
      rmask = mask, res = M - __builtin_popcount(mask);
  }
  {
    string _s = "res, rmask";
    replace(_s.begin(), _s.end(), ',', ' ');
    stringstream _ss(_s);
    istream_iterator<string> _it(_ss);
    __kumaerr(_it, res, rmask);
  };
}
void solve() {
  vector<int> cont(N, 0);
  UF uf(N);
  sort(E, E + M);
  int res = 0;
  for (int i = 0; i < (M); ++i) {
    long long y;
    int u, v;
    tie(y, u, v) = E[i];
    int p1 = uf.find(u), p2 = uf.find(v);
    bool merged = p1 != p2;
    int p = uf.unite(u, v, y);
    if (merged) {
      cont[p] = cont[p1] + cont[p2];
    }
    if (uf.ok(p)) {
      res -= cont[p];
      cont[p] = uf.cntE[p];
      res += cont[p];
    }
  }
  cout << M - res << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(12) << fixed;
  cin >> N >> M;
  for (int i = 0; i < (N); ++i) cin >> X[i];
  for (int i = 0; i < (M); ++i) {
    int u, v;
    long long y;
    cin >> u >> v >> y;
    --u, --v;
    E[i] = {y, u, v};
  }
  solve();
  return 0;
}
