#include <bits/stdc++.h>
using namespace std;
int weights[100024];
vector<tuple<int, int, int> > edges;
int now_time;
vector<tuple<int, int> > undo1[100024];
vector<tuple<int, int> > undo2[100024];
int sumWeights[100024];
int parents[100024];
int root(int a) {
  int parent = parents[a];
  if (parent == a) {
    return a;
  }
  int ans = root(parent);
  if (parent != ans) {
    undo1[now_time].emplace_back(a, parents[a]);
    parents[a] = ans;
  }
  return ans;
}
int root2(int a) {
  int parent = parents[a];
  if (parent == a) {
    return a;
  }
  return root2(parent);
}
int flag = 0;
void unite(int a, int b) {
  a = root(a);
  b = root(b);
  if (a != b) {
    ++flag;
    if (flag & 1) {
      undo1[now_time].emplace_back(b, parents[b]);
      undo2[now_time].emplace_back(a, sumWeights[a]);
      parents[b] = a;
      sumWeights[a] += sumWeights[b];
    } else {
      undo1[now_time].emplace_back(a, parents[a]);
      undo2[now_time].emplace_back(b, sumWeights[b]);
      parents[a] = b;
      sumWeights[b] += sumWeights[a];
    }
  }
}
int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &weights[i]);
    sumWeights[i] = weights[i];
    parents[i] = i;
  }
  for (int i = 0; i < M; ++i) {
    int a, b, y;
    scanf("%d%d%d", &a, &b, &y);
    edges.emplace_back(y, a - 1, b - 1);
  }
  sort(edges.begin(), edges.end());
  for (now_time = 0; now_time < M; ++now_time) {
    int y = get<0>(edges[now_time]);
    int a = get<1>(edges[now_time]);
    int b = get<2>(edges[now_time]);
    unite(a, b);
  }
  int ret = 0;
  for (now_time = M - 1; 0 <= now_time; --now_time) {
    int y = get<0>(edges[now_time]);
    int a = get<1>(edges[now_time]);
    int b = get<2>(edges[now_time]);
    int rt = root2(a);
    if (sumWeights[rt] < y) {
      ++ret;
      for (auto& undo : undo1[now_time]) {
        parents[get<0>(undo)] = get<1>(undo);
      }
      for (auto& undo : undo2[now_time]) {
        sumWeights[get<0>(undo)] = get<1>(undo);
      }
    }
  }
  printf("%d\n", ret);
  return 0;
}
