import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,m = LI()
    x = LI()
    s = sum(x)
    e = collections.defaultdict(list)
    for _ in range(m):
        a,b,y = LI()
        a -= 1
        b -= 1
        if y > s:
            continue
        e[a].append((b,y))
        e[b].append((a,y))

    b = [None] * n
    def ff(i):
        b[i] = 1
        s = x[i]
        ss = set([i])
        for c,y in e[i]:
            if b[c]:
                continue
            cs, css = ff(c)
            s += cs
            ss |= css
        return (s,ss)

    for i in range(n):
        if b[i]:
            continue
        f = 1
        while f:
            f = 0
            s,ss = ff(i)
            for t in ss:
                tf = None
                for c,y in e[t]:
                    if y > s:
                        tf = 1
                        break
                if tf is None:
                    continue
                f = 1
                e[t] = [(c,y) for c,y in e[t] if y <= s]
            if f:
                for t in ss:
                    b[t] = None

    r = m * 2
    for i in range(n):
        r -= len(e[i])

    return r // 2



print(main())


