N,M = map(int,input().split())
*X, = map(int,input().split())
ABY = [list(map(int,input().split())) for _ in [0]*M]

ABY = [(a-1,b-1,y) for a,b,y in ABY]
ABY.sort(key = lambda x:x[2])

import sys
sys.setrecursionlimit(10**7)

class UnionFind:
    def __init__(self,N,X):
        self.Parent = list(range(N))
        self.Weight = X[:]
    def get_Parent(self,n):
        if self.Parent[n] == n:return n
        p = self.get_Parent(self.Parent[n])
        self.Parent[n] = p
        return p
    def get_Weight(self,n):
        n = self.get_Parent(n)
        return self.Weight[n]
    def merge(self,x,y):
        x = self.get_Parent(x)
        y = self.get_Parent(y)
        if x!=y:
            self.Parent[y] = x
            self.Weight[x] += self.Weight[y]
        return
    def is_united(self,x,y):
        return self.get_Parent(x)==self.get_Parent(y)

#最小全域木を作る
U0 = UnionFind(N,[0]*N)
E = [0]*M
Et = [[] for _ in [0]*N]
for i,aby in enumerate(ABY):
    a,b,y = aby
    if U0.is_united(a,b):
        E[i] = -1 #-1 : 最小全域木に使わない
        continue
    U0.merge(a,b)
    Et[a].append((b,y,i))
    Et[b].append((a,y,i))

import heapq
hpush = heapq.heappush
hpop = heapq.heappop

U_final = UnionFind(N,X)
for i,aby in enumerate(ABY):
    if E[i] != 0: continue
    a,b,y = aby

    if U_final.get_Weight(a) + U_final.get_Weight(b) >= y:
        U_final.merge(a,b)
        E[i] = 3 #3 : 本決め使用
        continue

    hq = [(y,i)]
    U_tmp = UnionFind(N,X)

    while hq:
        y1,i1 = hpop(hq)
        a,b,_ = ABY[i1]
        E[i1] = 1 #1 : 仮決めの仮定
        U_tmp.merge(a,b)
        q = [a,b]
        while q:
            j = q.pop()
            for k,y2,ek in Et[j]:
                if E[ek] == 4 : continue
                if U_tmp.is_united(j,k) : continue
                if E[ek] == 3:
                    U_tmp.merge(j,k)
                    q.append(k) 
                    continue
                if y2 > y1 :
                    hpush(hq,(y2,ek))
                    continue
                E[ek] = 2 #2 : 仮決め従属で使用
                U_tmp.merge(j,k)
        if U_tmp.get_Weight(a) >= y1:break
    else:
        for j in range(M):
            if E[j] == 1: E[j] = 4
            elif E[j] == 2: E[j] = 0
        continue
    for j in range(M):
        if E[j] == 1 or E[j] == 2:
            a,b,_ = ABY[j]
            E[j] = 3
            U_final.merge(a,b)

for j in range(M):
    if E[j] != -1: continue
    a,b,y = ABY[j]
    if not U_final.is_united(a,b):
        E[j] = 4
    elif U_final.get_Weight(a) >= y:
        E[j] = 3
    else:
        E[j] = 4

print(E.count(4))
