import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1

class UnionFind:
    def __init__(self, n):
        self.state = [-1] * n
        self.weight = [0] * n
        self.state0 = []
        self.weight0 = []
        # self.size_table = [1] * n
        # cntはグループ数
        # self.cnt = n

    def save(self):
        self.state0 = self.state[:]
        self.weight0 = self.weight[:]

    def restore(self):
        self.state = self.state0[:]
        self.weight = self.weight0[:]

    def root(self, u):
        v = self.state[u]
        if v < 0: return u
        self.state[u] = res = self.root(v)
        return res

    def merge(self, u, v):
        ru = self.root(u)
        rv = self.root(v)
        if ru == rv: return
        du = self.state[ru]
        dv = self.state[rv]
        if du > dv: ru, rv = rv, ru
        if du == dv: self.state[ru] -= 1
        self.state[rv] = ru
        self.weight[ru] += self.weight[rv]
        # self.cnt -= 1
        # self.size_table[ru] += self.size_table[rv]
        return

    def get_weight(self, u):
        r = self.root(u)
        return self.weight[r]

def main():
    n, m = map(int, input().split())
    xx = list(map(int, input().split()))
    edges = []
    for _ in range(m):
        a, b, y = map(int, input().split())
        a, b = a - 1, b - 1
        edges.append([a, b, y])

    uf = UnionFind(n)
    for i, x in enumerate(xx):
        uf.weight[i] = x
    uf.save()
    kill = [False] * m
    ans = 0
    while 1:
        cnt_kill = 0
        for i, (a, b, y) in enumerate(edges):
            if kill[i]: continue
            uf.merge(a, b)
        for i, (a, b, y) in enumerate(edges):
            if kill[i]: continue
            if y > uf.get_weight(a):
                kill[i] = True
                cnt_kill += 1
        if cnt_kill == 0:
            break
        ans += cnt_kill
        uf.restore()
    print(ans)

main()
