IN = lambda:list(map(int, input().split()))
n, m = IN()
n = n + 1

W = [0] + IN()
E = [IN() for i in range(m)]
E.sort(key = lambda x:x[2])

P = list(range(n))
R = [0] * n
C = [0] * n

def find(x):
    if P[x] != x:
        P[x] = find(P[x])
    return P[x]

def union(x, y, w):
    p, q = find(x), find(y)
    if R[p] < R[q]: 
        p, q = q, p
    P[q] = p
    R[p] += R[p] == R[q]
    W[p] += W[q]
    C[p] = C[p] + C[q]+ 1 if W[p] < w else 0

for u, v, w in E:
    if find(u) == find(v):
        C[find(u)] += W[find(u)] < w
    else:
        union(u, v, w)

print(sum(C[i] for i in set(P)))