import sys
from collections import defaultdict as dd
input = sys.stdin.readline
N, M = map(int, input().split())

a = [0] + list(map(int, input().split()))
edg = []
for i in range(1, M + 1):
  u, v, c = map(int, input().split())
  edg.append((u, v, c, i))


def check(x):
  e = dd(list)
  for u, v, c, i in edg:
    if c > x: continue
    e[u].append((v, c, i))
    e[v].append((u, c, i))

  vis = [0] * (N + 1)
  evis = [0] * (M + 1)
  for i in range(1, N + 1):
    if vis[i]: continue
    s = [i]
    vs = 0
    es = 0
    while len(s):
      p = s.pop()
      if vis[p]: continue
      vis[p] = 1
      vs += a[p]
      for q, c, k in e[p]:
        if evis[k]: continue
        es = max(es, c)
        evis[k] = 1
        s.append(q)
    if vs < es: return False
  return True

ok = 0
ng = sum(a) + 1
while ng - ok > 1:
  m = (ok + ng) // 2
  if check(m): ok = m
  else: ng = m

res = 0
for _, _, c, _ in edg: res += c > ok
print(res)