#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const long long LINF = 1e18;
const double PI = acos(-1);
struct Edge {
 public:
  int from, to, cost;
  Edge() {}
  Edge(int _from, int _to, int _cost) {
    from = _from;
    to = _to;
    cost = _cost;
  }
  bool operator<(const Edge& e) const { return cost < e.cost; }
};
int N, M;
vector<vector<Edge> > G;
vector<int> X;
long long bfs(int s) {
  queue<int> Q;
  Q.push(s);
  vector<bool> visited(N);
  visited[s] = true;
  long long ret = 0;
  while (!Q.empty()) {
    int v = Q.front();
    Q.pop();
    ret += X[v];
    for (Edge e : G[v]) {
      if (visited[e.to]) continue;
      visited[e.to] = true;
      Q.push(e.to);
    }
  }
  return ret;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> M;
  X = vector<int>(N);
  for (int i = 0; i < (N); i++) cin >> X[i];
  G = vector<vector<Edge> >(N);
  vector<Edge> E;
  for (int i = 0; i < (M); i++) {
    int a, b, y;
    cin >> a >> b >> y;
    a--;
    b--;
    G[a].push_back(Edge(a, b, y));
    G[b].push_back(Edge(b, a, y));
    E.push_back(Edge(a, b, y));
  }
  sort((E).begin(), (E).end());
  reverse((E).begin(), (E).end());
  int ans = 0;
  for (int i = 0; i < (M); i++) {
    Edge e = E[i];
    if (bfs(e.from) < e.cost) {
      ans++;
      for (int i = 0; i < ((int)(G[e.from]).size()); i++) {
        if (G[e.from][i].to == e.to) {
          G[e.from].erase(G[e.from].begin() + i);
        }
      }
      for (int i = 0; i < ((int)(G[e.to]).size()); i++) {
        if (G[e.to][i].to == e.from) {
          G[e.to].erase(G[e.to].begin() + i);
        }
      }
    }
  }
  cout << ans << endl;
  system("pause");
  return 0;
}
