n, m = map(int, input().split())
nums = list(map(int, input().split()))
l = []
w = []
suv = [0]*n
d = 0
_sum = sum(nums)
for i in range(m):
  a, b, y = map(int, input().split())
  suv[a-1] += 1
  suv[b-1] += 1
  l.append((a, b))
  w.append(y)
while True:
  w_ = w[:]
  l_ = l[:]
  w = []
  for (i, y_) in enumerate(w_):
    if y_ > _sum:
      d += 1
      del_a, del_b = l[i]
      suv[del_a-1] -= 1
      suv[del_b-1] -= 1
    else:
      w.append(y_)
      l.append(l_[i])

  if 0 in suv:
    for (i, s) in enumerate(suv):
      if s == 0:
        _sum -= nums[i]
        nums.pop(i)
        suv.pop(i)
  else:
    break

print(d)