#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }




struct UnionFind {
    vector<int> par;
    vector<long long> w;
    
    UnionFind(int n, vector<long long> w) : par(n, -1), w(w) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        w[x] += w[y];
        return true;
    }

    long long get(int x) {
        x = root(x);
        return w[x];
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};


/* debug */
ostream& operator << (ostream& s, UnionFind uf) {
    map<int, vector<int> > res;
    for (int i = 0; i < uf.par.size(); ++i) {
        int r = uf.root(i);
        res[r].push_back(i);
    }
    for (map<int, vector<int> >::iterator it = res.begin(); it != res.end(); ++it) {
        s << endl;
        for (int j = 0; j < (int)it->second.size(); ++j) {
            s << it->second[j] << ", ";
        }
    }
    return s << endl;
}


int N, M;
vector<long long> X;

using pint = pair<int,int>;
using Edge = pair<long long, pint>;

int main () {
    while (cin >> N >> M) {
        X.resize(N);
        vector<Edge> edges;
        for (int i = 0; i < N; ++i) cin >> X[i];
        for (int i = 0; i < M; ++i) {
            int a, b;
            long long w;
            cin >> a >> b >> w;
            --a, --b;
            edges.push_back(Edge(w, pint(a, b)));
        }
        sort(edges.begin(), edges.end());

        // queries
        vector<int> left(M, 0), right(M, M + 1);
        while (true) {
            vector<vector<int> > distToQueries(M + 2);
            bool update = false;
            for (int q = 0; q < M; ++q) {
                if (right[q] - left[q] > 1) {
                    update = true;
                    int mid = (left[q] + right[q]) / 2;
                    distToQueries[mid].push_back(q);
                }
            }
            if (!update) break;
            UnionFind uf(N, X);
            for (int mid = 0; mid <= M; ++mid) {
                for (auto q : distToQueries[mid]) {
                    Edge e = edges[q];
                    int u = edges[q].second.first, v = edges[q].second.second;
                    if (uf.issame(u, v) && 
                        uf.get(edges[q].second.first) >= e.first) right[q] = mid;
                    else left[q] = mid;
                }
                if (mid == M) break;
                int u = edges[mid].second.first, v = edges[mid].second.second;
                uf.merge(u, v);
            }
        }

        vector<vector<int> > G(M);

        //COUT(G);
        
        queue<int> que;
        vector<int> dist(M, -1);
        for (int i = 0; i < M; ++i) {
            if (right[i] == M + 1) que.push(i), dist[i] = 0;
            else G[right[i]-1].push_back(i);
        }

        //COUT(G);

        int res = que.size();
        while (!que.empty()) {
            int v = que.front(); que.pop();
            for (auto nv : G[v]) {
                if (dist[nv] == -1) {
                    dist[nv] = dist[v] + 1;
                    que.push(nv);
                    ++res;
                }
            }
        }
        cout << res << endl;
    }   
}
















Measured memory_bytes: 9220