using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		var h=sc.La2;
		int n=s[0],m=s[1];
		var a=new int[m][];
		for(int i = 0;i<m;i++) {a[i]=sc.Ia;}
		Array.Sort(a,(u,v)=>u[2]-v[2]);
		Uf uf=new Uf(n+1);
		var d=new Uf.Nd[n-1];
		var g=new int[m];
		var f=new int[n-1];
		var z=new long[n-1];
		for(int i = 0,j=-1;i<m;i++) {
			var p1=uf.Root(a[i][0]);
			var p2=uf.Root(a[i][1]);
			if(uf.Union(p1,p2)){
				j++;
				int r=uf.Root(p1);
				d[j]=uf.c[r];
				z[j]=h[r]=h[p1]+h[p2];
				f[j]=uf.Size(r);
			}
			g[i]=j;
		}
		var b=new bool[n+1];
		int ans=0;
		for(int i = m-1;i>=0;i--) {
			if(b[a[i][0]]){continue;}
			if(a[i][2]<=z[g[i]]){
				var e=d[g[i]];
				for(int j = 0;j<f[g[i]];j++) {
					b[e.n]=true;
					e=e.ne;
				}
			}
			else{ans++;}
		}
		Console.WriteLine("{0}",ans);
	}
}
public class Uf{
	public class Nd{
		public int n;
		public Nd ne;
		public Nd(int n){this.n=n;}
	}
	private int[] arr,hi;
	public Nd[] c,l;
	public int all;
	public Uf(int n){
		arr=new int[n];
		hi=new int[n];
		c=new Nd[n];
		l=new Nd[n];
		all=n;
		for(int i=0;i<n;i++){
			arr[i]=-1;
			c[i]=l[i]=new Nd(i);
		}
	}
	public bool Union(int a,int b){
		a=Root(a);
		b=Root(b);
		if(a!=b){
			if(hi[a]<hi[b]){
				int v=b;
				b=a;
				a=v;
			}
			arr[a]+=arr[b];
			hi[a]=Math.Max(hi[a],hi[b]+1);
			arr[b]=a;
			all--;
			l[a].ne=c[b];
			l[a]=l[b];
			return true;
		}
		return false;
	}
	public bool Same(int a,int b){return Root(a)==Root(b);}
	public int Size(int a){return -arr[Root(a)];}
	public int Root(int a){return arr[a]<0?a:arr[a]=Root(arr[a]);}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);}
	public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 33640