import sys
def input():
	return sys.stdin.buffer.readline()[:-1]
sys.setrecursionlimit(10 ** 6)

class UnionFind():
	def __init__(self, lis):
		self.table = [-1 for _ in range(len(lis))]
		self.size = [x for x in lis]

	def find(self, x):
		if self.table[x] < 0:
			return x
		else:
			self.table[x] = self.find(self.table[x])
			return self.table[x]

	def unite(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 != s2:
			if self.table[s1] > self.table[s2]:
				self.table[s2] = s1
				self.table[s1] -= 1
				self.size[s1] += self.size[s2]
				self.size[s2] = 0
			else:
				self.table[s1] = s2
				self.table[s2] -= 1
				self.size[s2] += self.size[s1]
				self.size[s1] = 0
		return

n, m = map(int, input().split())
x = list(map(int, input().split()))
adj = [[] for _ in range(n)]
e = []
for i in range(m):
	a, b, y = map(int, input().split())
	a, b = a-1, b-1
	e.append((y, a, b))

used = [False for _ in range(m)]
candidate = [False for _ in range(m)]
e.sort()
uf = UnionFind(x)
for i in range(m):
	y, a, b = e[i]
	adj[a].append((b, y, i))
	adj[b].append((a, y, i))
	uf.unite(a, b)
	if uf.size[uf.find(a)] >= y:
		candidate[i] = True

ans = 0
for i in range(m-1, -1, -1):
	if used[i]:
		continue
	if not candidate[i]:
		ans += 1
	else:
		used[i] = True
		y, a, b = e[i]
		stack = [a, b]
		while stack:
			l = stack.pop()
			for v, z, j in adj[l]:
				if used[j]:
					continue
				if z <= y:
					stack.append(v)
					used[j] = True

print(ans)