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)]

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
      
  return update

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

print(ans)