import sys
input = sys.stdin.readline
from collections import deque
class Unionfindtree:
    def __init__(self, number,L):
        self.par = [i for i in range(number)]
        self.rank = [0] * (number)
        self.cost = L
        self.count = [0] * (number)

    def find(self, x):  # 親を探す
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):  # x,yを繋げる
        px = self.find(x)
        py = self.find(y)
        if px == py:
            self.count[py]+=1
            return
        if self.rank[px] < self.rank[py]:
            self.par[px] = py
            self.cost[py]+=self.cost[px]
            self.count[py]+=self.count[px]+1
        else:
            self.par[py] = px
            self.cost[px]+=self.cost[py]
            self.count[px]+=self.count[py]+1
        if self.rank[px] == self.rank[py]:
            self.rank[px] += 1

    def connect(self, x, y):  # 親が同じかみる
        return self.find(x) == self.find(y)



N,M=map(int,input().split())
X=[int(i) for i in input().split()]
que=[]
table=[[] for i in range(N)]
for i in range(M):
    a,b,c=map(int,input().split())
    a,b=a-1,b-1
    que.append((c,a,b))

que.sort()
T=Unionfindtree(N,X)
used=0
for i in range(M):
    c,a,b=que[i]
    T.union(a,b)
    if T.cost[T.find(a)]>=c:
        used+=T.count[T.find(a)]
        T.count[T.find(a)]=0
    #print(T.count)
    #print(T.par)

print(M-used)
