import sys
input = sys.stdin.readline
from collections import deque
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)

Group = [i for i in range(N+1)]

def find(x):
    while Group[x] != x:
        x = Group[x]
    return x

def Union(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(y)] = WEIGHTSUM[find(x)] + WEIGHTSUM[find(y)]
        Union(x, y)

    if w <= WEIGHTSUM[find(x)]:
        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))

