from sys import stdin
from itertools import repeat
def main():
    n, m = map(int, stdin.readline().split())
    w = map(int, stdin.readline().split())
    dat = map(int, stdin.read().split(), repeat(10, 3 * m))
    e = [(dat[i*3+2], dat[i*3] - 1, dat[i*3+1] - 1) for i in xrange(m)]
    e.sort()
    p = range(n)
    ok = [0] * n
    h = [None] * n
    g = [None] * m
    st = []
    pu = st.append
    for i, z in enumerate(e):
        c, u, v = z
        x = u
        while x != p[x]:
            pu(x)
            x = p[x]
        pu(x)
        t = x
        x = v
        while x != p[x]:
            pu(x)
            x = p[x]
        for y in st:
            p[y] = x
        del st[:]
        if x != t:
            w[x] += w[t]
            if w[x] >= c:
                ok[i] = 1
            g[i] = (h[x], h[t])
            h[x] = i
        elif w[x] >= c:
            ok[i] = 1
            g[i] = (h[x],)
            h[x] = i
    d = [0] * m
    po = st.pop
    for i in xrange(m - 1, -1, -1):
        if d[i]:
            continue
        pu(i)
        while st:
            x = po()
            d[x] = 1
            if g[x] is None:
                continue
            for y in g[x]:
                if y is not None:
                    ok[y] |= ok[x]
                    pu(y)
    print m - sum(ok)
main()
