import heapq

n, m = map(int, input().split())
xs = list(map(int, input().split()))
graph = [[] for i in range(n)]
edges = []
for i in range(m):
    a, b, y = map(int, input().split())
    graph[a - 1].append((b - 1, y))
    graph[b - 1].append((a - 1, y))
    heapq.heappush(edges, (-y, a-1, b-1))


def dfs_x(v):
    """
    連結成分の点コストの合計を求める
    """
    if visited_x[v]:
        return 0
    visited_x[v] = True
    v_cost = xs[v]
    for nv, y in graph[v]:
        v_cost += dfs_x(nv)
    return v_cost


def dfs_y(v, total_x):
    """
    合計の点コストより辺コストの大きい辺を削除する
    """
    if visited_y[v] or fixed[v]:
        return 0
    visited_y[v] = True
    del_cnt = 0
    valid_edges = []
    for nv, y in graph[v]:
        if y <= total_x:
            valid_edges.append((nv, y))
        else:
            if (v, y) in graph[nv]:
                graph[nv].remove((v, y))
                del_cnt += 1
        del_cnt += dfs_y(nv, total_x)
    graph[v] = valid_edges
    return del_cnt


delete_cnt = 0
fixed = [False] * n
while edges:
    minus_y, a, b = heapq.heappop(edges)
    y = -minus_y
    if (b, y) not in graph[a] or fixed[a]:
        continue
    visited_x = [False] * n
    total_x = dfs_x(a)
    if y <= total_x:
        for i in range(n):
            fixed[i] |= visited_x[i]
    else:
        visited_y = [False] * n
        delete_cnt += dfs_y(a, total_x)
print(delete_cnt)
