from collections import deque
import operator

N, M = map(int, input().split())
*X, = map(int, input().split())
E = []
for i in range(M):
    a, b, y = map(int, input().split())
    E.append((y, a-1, b-1))
E.sort()
*Y, = map(operator.itemgetter(0), E)

*p, = range(N)
def root(x):
    if x == p[x]:
        return x
    p[x] = y = root(p[x])
    return y

A = X[:]
def unite(x, y):
    px = root(x); py = root(y)
    if px == py:
        return 0
    if px < py:
        p[py] = px
        A[px] += A[py]
    else:
        p[px] = py
        A[py] += A[px]
    return 1

G = [[] for i in range(M)]
B = [0]*M
C = [-1]*N

ans = 0
for i, (y, a, b) in enumerate(E):
    pa = root(a); pb = root(b)
    ca = C[pa]; cb = C[pb]
    if unite(a, b):
        if ca != -1:
            G[i].append(ca)
        if cb != -1:
            G[i].append(cb)
        pa = root(a)
    else:
        if ca != -1:
            G[i].append(ca)
    B[i] = A[pa]
    C[pa] = i

if N > 1 and sum(X) < E[C[0]][0]:
    que = deque()
    que.append(C[0])
    while que:
        v = que.popleft()
        if B[v] < Y[v]:
            ans += 1
            que.extend(G[v])
print(ans)