#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
typedef long long LL;
const int N=100005;
int n,m;
struct qq	{int x,y,c;}e[N];
int a[N];
int siz[N];
bool cmp (qq x,qq y)	{return x.c<y.c;}
int fa[N];
int find_fa (int x)	{return fa[x]==x?x:fa[x]=find_fa(fa[x]);}
int in[N];
int ans=0,sum=0;
struct qt
{
	int son[2],fa;
	int val;
	LL sum,sum1;//权值和   轻儿子的权值和 
	bool rev;
}tr[N];
void Push_down (int now)
{
	int s1=tr[now].son[0],s2=tr[now].son[1];
	if (tr[now].rev)
	{
		tr[now].rev^=1;tr[s1].rev^=1;tr[s2].rev^=1;
		swap(tr[now].son[0],tr[now].son[1]);
	}
}
void update (int x)
{
	int s1=tr[x].son[0],s2=tr[x].son[1];
	tr[x].sum=tr[s1].sum+tr[s2].sum+tr[x].sum1+tr[x].val;
}
bool Is_root (int x)	{int ff=tr[x].fa;return (tr[ff].son[0]!=x&&tr[ff].son[1]!=x);}
void rotate (int x)
{
    int y=tr[x].fa,z=tr[y].fa,r,R;
    int w=(tr[y].son[0]==x);
     
    r=tr[x].son[w];R=y;
    tr[R].son[1-w]=r;
    if (r!=0) tr[r].fa=R;
     
    r=x;R=z;
    if (!Is_root(y))
    {
        if (tr[R].son[0]==y) tr[R].son[0]=r;
        else tr[R].son[1]=r;
    }
    if (r!=0) tr[r].fa=R;
     
    r=y;R=x;
    tr[R].son[w]=r;
    if (r!=0) tr[r].fa=R;
     
    update(y);update(x);update(z);
}
void PD (int x)
{
	if (!Is_root(x)) 
	{
		PD(tr[x].fa);
	}
	Push_down(x);
}
void Splay (int x)
{
	update(x);PD(x);
	while (!Is_root(x))
	{
		int y=tr[x].fa,z=tr[y].fa;
		update(x);update(y);update(z);
		if (!Is_root(y))
		{
			if ((tr[z].son[0]==y)==(tr[y].son[0]==x)) rotate(y);
			else rotate(x);
		}
		rotate(x);
	}
}
void Access (int x)
{
	int last=0;
	while (x!=0)
	{
		Splay(x);
		int xx=tr[x].son[1];
		tr[x].sum1=tr[x].sum1+tr[xx].sum-tr[last].sum;
		tr[x].son[1]=last;last=x;
		update(x);
		x=tr[x].fa;
	}
}
void make_root (int x)
{
	Access(x);
	Splay(x);
	tr[x].rev^=1;
	Push_down(x);
}
void link (int x,int y)
{
	make_root(x);
	make_root(y);
	tr[x].fa=y;
	tr[y].sum1+=tr[x].sum;
	update(y);
}
void cut (int x,int y)
{
	make_root(x);Access(y);Splay(y);
	if (tr[x].fa==y)	tr[x].son[1]=0;

	tr[x].fa=0;tr[y].son[0]=0;
	update(x);update(y);
	make_root(x);make_root(y);
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int u=1;u<=n;u++) 	
	{
		scanf("%d",&tr[u].val);
		tr[u].sum=tr[u].val;
		fa[u]=u;
	}
	for (int u=1;u<=m;u++)	scanf("%d%d%d",&e[u].x,&e[u].y,&e[u].c);
	sort(e+1,e+1+m,cmp);
	for (int u=1;u<=m;u++)
	{
		int x=find_fa(e[u].x),y=find_fa(e[u].y);
		if (x==y) continue;
		fa[x]=y;link(e[u].x,e[u].y);
		in[u]=true;
	}
	for (int u=m;u>=1;u--)
	{
		int x=e[u].x,y=e[u].y;
		if (in[u]==false) continue;
		make_root(x);	
		int s1=tr[x].son[0],s2=tr[x].son[1];
		/*printf("YES:\n");
		printf("%d %d\n",x,y);
		printf("%d %d %d %d %d\n",tr[x].sum,tr[x].sum1,tr[x].val,s1,s2);
		printf("%d %d %d\n",tr[s1].sum,tr[s1].sum1,tr[s1].val);
		printf("%d %d %d\n",tr[s2].sum,tr[s2].sum1,tr[s2].val);*/
		if (tr[x].sum<e[u].c)	{cut(x,y);in[u]=false;}
	}
	for (int u=1;u<=n;u++) fa[u]=u;
	for (int u=1;u<=m;u++)
	{
		int x=find_fa(e[u].x),y=find_fa(e[u].y);
		if (in[u])	fa[x]=y;
	}
	for (int u=1;u<=m;u++)
	{
		if (in[u]==false)
		{
			if (find_fa(e[u].x)!=find_fa(e[u].y))	ans++;
			else
			{
				make_root(e[u].x);
				if (tr[e[u].x].sum<e[u].c)	ans++;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 6912