#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> void Max(T &m, const T q) { if (m < q) m = q; }
template<typename T> void Min(T &m, const T q) { if (m > q) m = q; }
template<typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

struct SizeAwareUnionFind
{
    vector<lint> par;
    vector<plint> cou;
    SizeAwareUnionFind(int N) : par(N), cou(N) { REP(i, N) par[i] = i, cou[i] = plint(1, 0); }
    int find(int x) { return (par[x] == x) ? x : (par[x] = find(par[x])); }
    void unite(int x, int y) {
        x = find(x), y = find(y); if (x == y) return;
        par[y] = x, cou[x].first += cou[y].first;
    }
    lint weight(int x) { return cou[find(x)].first; }
    bool same(int x, int y) { return find(x) == find(y); }
};

vector<pair<pint, lint>> edges;
map<int, vector<plint>> n_e;

map<int, set<int>> chi, par;

int ans;
SizeAwareUnionFind uf(1);
set<int> visited;

vector<int> status;
map<int, set<int>> ma_dfs2;

set<int> updated;
void dfs2(int e_now)
{
    if (status[e_now] == 1)
    {
        for (auto nxt : ma_dfs2[e_now])
        {
            status[nxt] = 1;
        }
    }
    for (auto nxt : ma_dfs2[e_now]) dfs2(nxt);
}

int main()
{
    int N, M;
    cin >> N >> M;
    vector<lint> weights(N + 1);
    REP(i, N) cin >> weights[i + 1];

    uf = SizeAwareUnionFind(N + 1);
    REP(i, N + 1)
    {
        uf.cou[i].first = weights[i];
        uf.cou[i].second = -1;
    }

    edges.resize(M);
    REP(i, M)
    {
        int A, B;
        lint Y;
        cin >> A >> B >> Y;
        edges[i].first = make_pair(A, B);
        edges[i].second = Y;
        n_e[A].push_back(plint(Y, i));
        n_e[B].push_back(plint(Y, i));
    }

    for (auto pa : n_e)
    {
        vector<plint> vec = pa.second;
        sort(vec.rbegin(), vec.rend());
        REP(i, vec.size() - 1) chi[vec[i].second].insert(vec[i + 1].second);
    }

    for (auto pa : chi)
    {
        for (auto v : pa.second) par[v].insert(pa.first);
    }

    ans = 0;
    status.resize(M, 0);
    priority_queue<plint, vector<plint>, greater<plint>> pq;
    REP(e, M) pq.push(plint(edges[e].second, e));

    while (!pq.empty())
    {
        plint pa = pq.top();
        pq.pop();
        lint w = pa.first;
        int e = pa.second;
        ma_dfs2[e].insert(uf.cou[uf.find(edges[e].first.first)].second);
        ma_dfs2[e].insert(uf.cou[uf.find(edges[e].first.second)].second);
        ma_dfs2[e].erase(-1);
        uf.unite(edges[e].first.first, edges[e].first.second);
        uf.cou[uf.find(edges[e].first.first)].second = e;
        if (uf.weight(edges[e].first.first) >= w) status[e] = 1;
    }

    // dbg(status);
    // dbg(ma_dfs2);
    map<int, set<int>> par_dfs;
    for (auto pa : ma_dfs2)
    {
        for (auto v : pa.second) par_dfs[v].insert(pa.first);
    }
    REP(e, M) if (!par_dfs.count(e)) dfs2(e);
    // dbg(status);
    // dbg(edges);
    cout << M - accumulate(status.begin(), status.end(), 0) << endl;
}


Measured memory_bytes: 85104