from collections import defaultdict
class Unionfindtree:
    def __init__(self, number):
        self.par = [i for i in range(number)]
        self.rank = [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:
            return
        if self.rank[px] < self.rank[py]:
            self.par[px] = py
        else:
            self.par[py] = px
        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()]
num=0
x=sum(X)
table=[]
for i in range(M):
    a,b,c=map(int,input().split())
    a,b=a-1,b-1
    if c<=x:
        table.append((c,a,b))
        num+=1
test=sorted(table)
while True:
    #print(1)
    flag=True
    T=Unionfindtree(N)
    dd=defaultdict(int)
    for c,a,b in test:
        T.union(a,b)
    for i in range(N):
        dd[T.find(i)]+=X[i]
    ntest=[]
    for c,a,b in test:
        if dd[T.find(a)]<c:
            flag=False
        else:
            ntest.append((c,a,b))
    if flag:
        break
    test=ntest
print(M-len(test))