//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

using i8 = ::std::int_least8_t;
using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u8 = ::std::uint_least8_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;
using isize = ::std::ptrdiff_t;
using usize = ::std::size_t;

template <class T = usize> class rep {
	const T f, l;

public:
	class itr {
		friend rep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { ++i; }
		constexpr T operator*() const noexcept { return i; }
		constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr rep(const T first, const T last) noexcept : f(first), l(last) {}
	constexpr itr begin() const noexcept { return itr(f); }
	constexpr itr end() const noexcept { return itr(l); }
};
template <class T = usize> class revrep {
	const T f, l;

public:
	class itr {
		friend revrep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { --i; }
		constexpr T operator*() const noexcept { return i; }
		constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr revrep(const T first, const T last) noexcept : f(first), l(last) {}
	constexpr itr begin() const noexcept { return itr(l - 1); }
	constexpr itr end() const noexcept { return itr(f - 1); }
};
template <class T> bool amax(T &a, const T &b) {
	return a <= b ? (a = b, 1) : 0;
}
template <class T> bool amin(T &a, const T &b) {
	return b <= a ? (a = b, 1) : 0;
}
template <class T> bool asmax(T &a, const T &b) {
	return b <= a ? 0 : (a = b, 1);
}
template <class T> bool asmin(T &a, const T &b) {
	return a <= b ? 0 : (a = b, 1);
}
template <class T> using vec_alias = ::std::vector<T>;
template <class T> auto md_vec(usize n, const T &value) {
	return ::std::vector<T>(n, value);
}
template <class... Args> auto md_vec(usize n, Args... args) {
	return ::std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> const T &as_const(const T &v) noexcept { return v; }
template <class T> constexpr T difference(const T &a, const T &b) {
	return a <= b ? b - a : a - b;
}

#include <algorithm>
#include <iostream>
#include <utility>
#include <string>
#include <numeric>
#include <stack>
#include <tuple>

#include <cassert>
#include <cstddef>
#include <utility>

template <template <class> class Container> class union_find {
protected:
	class node_type;

public:
	using container_type = Container<node_type>;
	using size_type = typename container_type::size_type;

protected:
	class node_type {
	public:
		typename union_find::size_type parent, size;
	};
	container_type c;

public:
	union_find() : c() {}
	explicit union_find(const size_type size) : c(size, { 0, 1 }) {
		for (size_type i = 0; i < size; ++i)
			c[i].parent = i;
	}

	bool empty() const { return c.empty(); }
	size_type size() const { return c.size(); }

	size_type find(size_type x) {
		assert(x < size());
		while (c[x].parent != x)
			x = c[x].parent = c[c[x].parent].parent;
		return x;
	}
	bool same(const size_type x, const size_type y) {
		assert(x < size());
		assert(y < size());
		return find(x) == find(y);
	}
	size_type size(const size_type x) {
		assert(x < size());
		return c[find(x)].size;
	}

	::std::pair<size_type, size_type> unite(size_type x, size_type y) {
		assert(x < size());
		assert(y < size());
		x = find(x);
		y = find(y);
		if (x != y) {
			if (c[x].size < c[y].size)
				::std::swap(x, y);
			c[x].size += c[y].size;
			c[y].parent = x;
		}
		return { x, y };
	}
};



int main() {
	usize n, m;
	::std::cin >> n >> m;
	::std::vector<u64> x(n);
	struct edge {
		u64 cost;
		usize a, b;
		bool operator<(const edge &r)const {
			return cost < r.cost;
		}
	};
	::std::vector<edge> y(m);
	for (auto &e : x) {
		::std::cin >> e;
	}
	for (auto &e : y) {
		::std::cin >> e.a >> e.b >> e.cost;
		--e.a;
		--e.b;
	}
	usize ans = m;
	::std::sort(y.begin(), y.end());
	::std::vector<bool> use(n, true);
	union_find<vec_alias> uf(n);
	::std::vector<usize> yet(n, 0);
	for (const auto &e : y) {
		if (uf.same(e.a, e.b)) {
			if (x[uf.find(e.a)] < e.cost) {
				++yet[uf.find(e.a)];
			}
			else {
				ans -= 1;
			}
			continue;
		}
		usize r, c;
		::std::tie(r, c) = uf.unite(e.a, e.b);
		x[r] += x[c];
		yet[r] += yet[c] + 1;
		if (e.cost <= x[r]) {
			ans -= yet[r];
			yet[r] = 0;
		}
	}
	::std::cout << ans << ::std::endl;
	return 0;
}


Measured memory_bytes: 5760