class UnionFind(object):
    def __init__(self, size, weight):
        self.parent = [i for i in range(size)]
        self.rank = [0 for _ in range(size)]
        self.size = weight

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
            self.size[y]+=self.size[x]
        else:
            self.parent[y] = x
            self.size[x]+=self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)
      
    def get_size(self, x):
        x = self.find(x)
        return self.size[x]
from collections import defaultdict
N, M = map(int, input().split())
X = list(map(int, input().split()))
edge = []
G = [[] for _ in range(N)]
for _ in range(M):
    a, b, y = map(int, input().split())
    edge.append((y, a-1, b-1))
    G[a-1].append((b-1, y))
    G[b-1].append((a-1, y))
edge.sort()
U = UnionFind(N, X)
candidate = [False]*M
for i, e in enumerate(edge):
    y, a, b = e
    U.unite(a, b)
    if U.get_size(a)>=y:
        candidate[i] = True
is_used = defaultdict(lambda :False)
ans = 0
for i in range(M)[::-1]:
    y, a, b = edge[i]
    if is_used[(a, b)]:
        continue
    if candidate[i]:
        que = [a]
        is_used[(a, b)] = True
        is_used[(b, a)] = True
        while que:
            v = que.pop()
            ans+=1
            for nv, c in G[v]:
                if c<=y and not is_used[(v, nv)]:
                    que.append(nv)
                    is_used[(v, nv)] = True
                    is_used[(nv, v)] = True
print(M-ans)