def we(n,m,x,aby):
    aby.sort()
    aby=[[i[2],i[0],i[1]]for i in aby]

    p=[i for i in range(n+1)]
    r=[0]*(n+1)
    ba=[0]*(n+1)
    wt=x[:]

    def find(x):
        if p[x]!=x:
            p[x]=find(p[x])
        return p[x]
 
    def union(x,y,w):
        x,y=find(x),find(y)
        if r[x]<r[y]:x,y = y,x
        p[y]=x
        r[x] += r[x] == r[y]

        wt[x]+=wt[y]

        ba[x]+=ba[y]

        if wt[x]<w:
            ba[x]+=1
        else:
            ba[x]=0
    
    def add(x,w):
        x = find(x)
        if wt[x]<w:
            ba[x]+=1


    for y,a,b in aby:
        if find(a)==find(b):
            add(a,y)
        else:
            union(a,b,y)
    ans=0
    for i in range(1,n+1):
        if p[i]==i:
            ans+=ba[i]
    return ans



n,m=map(int,input().split())
print(we(n,m,[0]+[int(i) for i in input().split()],[list(map(int,input().split())) for i in range(m)]))
