#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 55;
signed main() {
  ll N, M;
  cin >> N >> M;
  ll X[N];
  ll node_point_sum = 0;
  for (ll i = 0; i < N; i++) {
    ll x;
    cin >> x;
    X[i] = x;
    node_point_sum += x;
  }
  ll connected_num[N];
  fill(connected_num, connected_num + N, 0);
  tuple<ll, ll, ll> edge_info[M];
  for (ll i = 0; i < M; i++) {
    ll a, b, y;
    cin >> a >> b >> y;
    a--;
    b--;
    edge_info[i] = make_tuple(y, a, b);
    connected_num[a]++;
    connected_num[b]++;
  }
  sort(edge_info, edge_info + M, greater<tuple<ll, ll, ll>>());
  ll ret = 0;
  for (ll i = 0; i < M; i++) {
    tuple<ll, ll, ll> e = edge_info[i];
    if (get<0>(e) <= node_point_sum) break;
    ret++;
    connected_num[get<1>(e)]--;
    if (connected_num[get<1>(e)] <= 0) {
      node_point_sum -= X[get<1>(e)];
    }
    connected_num[get<2>(e)]--;
    if (connected_num[get<2>(e)] <= 0) {
      node_point_sum -= X[get<2>(e)];
    }
  }
  cout << ret << endl;
  return 0;
}
