import sys


def solve(vertices):
    s = sum(xxx[v] for v in vertices)
    ans = 0
    for v in vertices:
        for l in list(links[v]):
            if l[0] > s:
                ans += 1
                links[v].remove(l)
    whole_checked = set()
    for r in vertices:
        if r in whole_checked:
            continue
        checked = set()
        q = [(r, None)]
        while q:
            v, p = q.pop()
            if v in checked:
                continue
            checked.add(v)
            q.extend((u, v) for y, u in links[v] if u != p)
        if len(checked) == len(vertices):
            break
        ans += solve(checked)
        whole_checked.update(checked)
    return ans


n, m = map(int, input().split())
xxx = list(map(int, input().split()))
links = [set() for _ in range(n)]
for line in sys.stdin.readlines():
    a, b, y = map(int, line.split())
    a -= 1
    b -= 1
    links[a].add((y, b))
    links[b].add((y, a))

print(solve(set(range(n))) // 2)
