import sys
from collections import deque
input = sys.stdin.readline

N,M=map(int,input().split())
X=list(map(int,input().split()))
EDGE=[list(map(int,input().split())) for i in range(M)]
EDGE.sort(key=lambda x:x[2])

EDGELIST=[[] for i in range(N+1)]
for i in range(M):
    x,y,w=EDGE[i]
    EDGELIST[x].append(i)
    EDGELIST[y].append(i)


#UnionFind
Group=[i for i in range(N+1)]#グループ分け.Group[i]=jのときiとjは同じグループ

def find(x):#find(a)=find(b)のとき同じグループ
    while Group[x] != x:
        x=Group[x]
    return x

def Union(x,y):#xとyが同じグループになるよう更新
    if find(x) != find(y):
        Group[find(y)]=Group[find(x)]=min(find(y),find(x))

USE=[0]*M
WEIGHTSUM=[0]+[X[i] for i in range(N)]

QUE=deque()

for i in range(M):
    x,y,w=EDGE[i]
    
    if find(x)!=find(y):
        WEIGHTSUM[find(x)]=WEIGHTSUM[find(x)]+WEIGHTSUM[find(y)]
        Union(x,y)

    if w<=WEIGHTSUM[find(x)]:
        #USE[i]=1
        QUE.append(i)


while QUE:
    q=QUE.pop()
    x,y,w=EDGE[q]

    NQUE=deque([q])

    while NQUE:
        nq=NQUE.pop()

        if USE[nq]==1:
            continue
        x,y,_=EDGE[nq]
        for e in EDGELIST[x]+EDGELIST[y]:

            if EDGE[e][2]<=w:
                NQUE.append(e)
        USE[nq]=1
    
print(USE.count(0))