/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes"<<"\n"
#define no cout<<"No"<<"\n"

vi x;
struct UnionFind{
    vector<int> data;
	vi num;
    UnionFind(int size){
		data=vi(size,-1);
		num=x;
	}
    bool unionSet(int x,int y){
        x=root(x);y=root(y);
        if(x==y)return 0;
        if(data[y]<data[x])swap(x,y);
        data[x]+=data[y],data[y]=x;
		num[x]+=num[y];num[y]=0;
        return 1;
    }
    bool findSet(int x,int y){
        return root(x)==root(y);
    }
    int root(int x){
        return data[x]<0 ? x : data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};
int n,m;
vvi G,out,cost;
void dfs(int a,int b){
	// cout<<a<<" "<<b<<endl;
	rep(i,G[a].size())if(out[a][i]>=0&&b>=cost[a][i]){
		out[a][i]=-1;
		dfs(G[a][i],b);
	}
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin>>n>>m;
	x=vi(n);
	rep(i,n)cin>>x[i];
	vvi in(m,vi(4));
	rep(i,m)cin>>in[i][1]>>in[i][2]>>in[i][0];
	rep(i,m)in[i][1]--,in[i][2]--;
	sort(all(in));
	G=vvi(n),cost=vvi(n);
	rep(i,m)G[in[i][1]].pb(in[i][2]),G[in[i][2]].pb(in[i][1]),cost[in[i][1]].pb(in[i][0]),cost[in[i][2]].pb(in[i][0]);
	out=G;

	UnionFind uf(n);
	rep(i,m){
		int it=i;
		while(it<m&&in[i][0]==in[it][0]){
			uf.unionSet(in[it][1],in[it][2]);
			it++;
		}
		while(i<it){
			if(uf.num[uf.root(in[i][1])]>=in[i][0])in[i][3]=1;
			i++;
		}
		i--;
	}
	// show2d(in);
	for(int i=m-1;i>=0;i--){
		if(in[i][3]){
			dfs(in[i][1],in[i][0]);
		}
	}
	int c=0;
	rep(i,n)rep(j,G[i].size())if(out[i][j]<0)c++;
	cout<<(2*m-c)/2<<endl;
}


Measured memory_bytes: 31104