#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, m;
ll x[100100];
struct edge {
    int a, b;
    ll y;
};
vector<edge> es;

struct info {
    ll w_sum;
    int num_e;
    int num_inval_e;
    ll y_max;
    int parent;
};

class UnionFind {
private:
    static const int MAX = 100100;
    info par[MAX];
    int r[MAX];
public:
    UnionFind(int n = MAX) {
        for (int i = 0; i < n; i++) {
            info v;
            v.w_sum = x[i];
            v.num_e = 0;
            v.num_inval_e = 0;
            v.y_max = 0;
            v.parent = -1;
            par[i] = v;
            r[i] = 0;
        }
    }

    int find(int x) {
        if (par[x].parent < 0) {
            return x;
        } else {
            return par[x].parent = find(par[x].parent);
        }
    }

    void unite(int x, int y, ll yw) {
        x = find(x);
        y = find(y);
        if (x == y) {
            par[x].num_e++;
            par[x].y_max = max(par[x].y_max, yw);
            if (par[x].y_max > par[x].w_sum) par[x].num_inval_e++;
            else par[x].num_inval_e = 0;
            return;
        }
        if (r[x] < r[y]) {
            par[y].w_sum += par[x].w_sum;
            par[y].num_e += par[x].num_e + 1;
            par[y].y_max = max(max(par[y].y_max, par[x].y_max), yw);
            if (par[y].y_max > par[y].w_sum) par[y].num_inval_e += par[x].num_inval_e + 1;
            else par[y].num_inval_e = 0;
            par[x].parent = y;
        } else {
            par[x].w_sum += par[y].w_sum;
            par[x].num_e += par[y].num_e + 1;
            par[x].y_max = max(max(par[x].y_max, par[y].y_max), yw);
            if (par[x].y_max > par[x].w_sum) par[x].num_inval_e += par[y].num_inval_e + 1;
            else par[x].num_inval_e = 0;
            par[y].parent = x;
            if (r[x] == r[y]) r[x]++;
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    bool valid(int x) {
        int v = find(x);
        return par[v].w_sum >= par[v].y_max;
    }

    int num_e(int x) {
        return par[find(x)].num_e;
    }
    int num_inval_e(int x) {
        return par[find(x)].num_inval_e;
    }
    
    info get(int x) {
        return par[find(x)];
    }
};

int solve() {
    sort(ALL(es), [](const edge& e0, const edge& e1){ return e0.y < e1.y; });
    UnionFind uf(n);
    int res = 0;
    for (int i = 0; i < m; i++) {
        edge e = es[i];
        if (!uf.same(e.a, e.b)) {
            int inval_e = uf.num_inval_e(e.a) + uf.num_inval_e(e.b);
            uf.unite(e.a, e.b, e.y);

            if (uf.valid(e.a)) res += inval_e+1;
        } else {
            int inval_e = uf.num_inval_e(e.a);
            uf.unite(e.a, e.b, e.y);
            if (uf.valid(e.a)) res++;
        }
        //info v = uf.get(e.a);
        //cerr << temp << " " << v.w_sum << " "  <<v.num_e << " " << v.y_max << endl;
    }
    return m - res;
}

void input() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> x[i];
    for (int i = 0; i < m; i++) {
        edge e;
        cin >> e.a >> e.b >> e.y;
        e.a--;
        e.b--;
        es.push_back(e);
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 6256