from collections import defaultdict

class UnionFind():
    def __init__(self, n=0):
        self.d = [-1]*n
    
    def find(self, x):
        if self.d[x] < 0: return x
        self.d[x] = self.find(self.d[x])
        return self.d[x]

    def unite(self, x, y):
        x,y=self.find(x),self.find(y)
        if x==y:return False
        if self.d[x] > self.d[y]: x,y=y,x
        self.d[x] += self.d[y]
        self.d[y] = x
        return True

    def same(self, x,y): return self.find(x)==self.find(y)
    def size(self,x): return -self.d[self.find(x)]
    
from collections import deque

def bfs(s,seen):
    p = X[s]
    MAX,argmax=0,-1
    todo = deque()
    seen[s]=1
    todo.append(s)
    while len(todo):
      a = todo.popleft()
      for b in G[a].keys():
        if seen[b] == 0:
          seen[b] = 1
          todo.append(b)
          if MAX < G[a][b]:
            MAX = G[a][b]
            argmax = tuple(sorted((a,b)))
          p += X[b]
    return p,MAX,argmax,seen

N,M=map(int,input().split())
*X,=map(int,input().split())
G=[{} for _ in range(N)]
uf = UnionFind(N)
sumX = sum(X)
ans=0
for i in range(M):
  a,b,c=map(int,input().split())
  if c>sumX:
    ans += 1
    continue
  G[a-1][b-1]=G[b-1][a-1]=c
  uf.unite(a-1,b-1)
  
def solve(ite):
  global uf,ans
  update=0
  if ite > 0:
    uf = UnionFind(N)
    for i in range(N):
      for j in G[i].keys():
        uf.unite(i,j)

    glist = defaultdict(set)
    plist=defaultdict(int)
    elist = defaultdict(dict)
    for i in range(N):
      if uf.d[i] != -1:
        g = uf.find(i)
        glist[g].add(i)
        plist[g] += X[i]
        tmp = {tuple(sorted((i,v))):G[i][v] for v in G[i].keys()}
        elist[g].update(tmp)

    for g in glist.keys():
      argmax,MAX = sorted(elist[g].items(),key=lambda x:x[1],reverse=True)[0]
      if MAX > plist[g]:
        v1,v2 = argmax
        del G[v1][v2],G[v2][v1]
        ans += 1
        update=1
        
  else:
    seen = [0]*N
    for i in range(N):
      if not seen[i] and len(G[i].keys()):
        p,MAX,argmax,seen = bfs(i,seen)
        if MAX>p:
          i,j = argmax
          del G[i][j],G[j][i]
          ans += 1
          update=1
    
  return update

i = 0
while 1:
  update = solve(i)
  i += 1
  if update == 0:
    break

print(ans)