#include <bits/stdc++.h>
using std::bitset;
using std::cerr;
using std::cin;
using std::cout;
using std::deque;
using std::endl;
using std::fill;
using std::fixed;
using std::ios_base;
using std::iterator;
using std::map;
using std::max_element;
using std::min_element;
using std::multimap;
using std::multiset;
using std::pair;
using std::queue;
using std::reverse;
using std::set;
using std::setprecision;
using std::sort;
using std::stable_sort;
using std::stack;
using std::string;
using std::swap;
using std::unique;
using std::vector;
long long min(long long a, long long b) { return a < b ? a : b; }
long long min(int a, long long b) { return a < b ? a : b; }
long long min(long long a, int b) { return a < b ? a : b; }
long long min(int a, int b) { return a < b ? a : b; }
long long max(long long a, long long b) { return a > b ? a : b; }
long long max(int a, long long b) { return a > b ? a : b; }
long long max(long long a, int b) { return a > b ? a : b; }
long long max(int a, int b) { return a > b ? a : b; }
namespace MySpace {};
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAXA = 0;
int f[MAXA];
int uf[MAXA];
long long inq(long long a, long long b) {
  if (b == 0) return 1;
  long long l = inq(a, b / 2);
  if (b % 2) return l * l % MOD * a % MOD;
  return l * l % MOD;
}
long long cnk(long long n, long long k) {
  if (k < 0 || k > n) return 0;
  return f[n] * uf[k] % MOD * uf[n - k] % MOD;
}
int n, m;
int x[500000];
int root[500000];
int sz[500000];
pair<int, pair<int, int> > e[500000];
int Root(int x) {
  if (x == root[x]) return x;
  return root[x] = Root(root[x]);
}
bool Merge(int a, int b) {
  a = Root(a), b = Root(b);
  if (a == b) {
    return 0;
  }
  if (sz[a] > sz[b]) {
    sz[a] += sz[b];
    root[b] = a;
    return 1;
  } else {
    sz[b] += sz[a];
    root[a] = b;
    return 1;
  }
}
vector<pair<pair<int, int>, long long> > edges;
vector<int> graph[500000];
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  long long s = 0;
  for (int i = 1; i <= n; i++) cin >> x[i], root[i] = i, sz[i] = 1, s += x[i];
  for (int i = 0; i < m; i++)
    cin >> e[i].second.first >> e[i].second.second >> e[i].first;
  sort(e, e + m);
  for (int i = 0; i < m; i++) {
    int x = Merge(e[i].second.first, e[i].second.second);
    if (x) {
      graph[e[i].second.first].push_back(edges.size());
      graph[e[i].second.second].push_back(edges.size());
      edges.push_back({{e[i].second.first, e[i].second.second}, s});
    }
  }
  int cnt = 0;
  for (int i = m - 1; i >= 0; i--) {
    int t = -1;
    int w = 0;
    for (int j = 0; j < edges.size(); j++) {
      if (edges[j].first == e[i].second) {
        t = j;
      }
      if (edges[j].first.first == e[i].second.first ||
          edges[j].first.second == e[i].second.first ||
          edges[j].first.first == e[i].second.second ||
          edges[j].first.second == e[i].second.second) {
        w = edges[j].second;
      }
    }
    if (w < e[i].first) {
      cnt++;
      if (t != -1) {
        int g = edges[t].first.first, h = edges[t].first.second;
        for (int r = t; r + 1 < edges.size(); r++) edges[r] = edges[r + 1];
        edges.pop_back();
        for (int v = 1; v <= n; v++)
          for (int j = 0; j < graph[v].size(); j++)
            if (graph[v][j] == t) {
              for (int k = j; k + 1 < graph[v].size(); k++)
                graph[v][k] = graph[v][k + 1];
              graph[v].pop_back();
              break;
            }
        for (int v = 1; v <= n; v++)
          for (int j = 0; j < graph[v].size(); j++)
            if (graph[v][j] >= t) graph[v][j]--;
        vector<int> visited(n + 1);
        vector<int> q1 = {g}, q2 = {h};
        vector<int> where(edges.size());
        visited[g] = 1, visited[h] = 1;
        long long gs = x[g], hs = x[h];
        for (int i = 0; i < q1.size(); i++) {
          for (int j = 0; j < graph[q1[i]].size(); j++) {
            where[graph[q1[i]][j]] = 1;
            int u = edges[graph[q1[i]][j]].first.first +
                    edges[graph[q1[i]][j]].first.second - i;
            if (visited[u]) continue;
            gs += x[u];
            q1.push_back(u);
            visited[u] = 1;
          }
        }
        for (int i = 0; i < q2.size(); i++) {
          for (int j = 0; j < graph[q2[i]].size(); j++) {
            where[graph[q2[i]][j]] = 2;
            int u = edges[graph[q2[i]][j]].first.first +
                    edges[graph[q2[i]][j]].first.second - i;
            if (visited[u]) continue;
            hs += x[u];
            q2.push_back(u);
            visited[u] = 1;
          }
        }
        for (int i = 0; i < edges.size(); i++)
          if (where[i] == 1)
            edges[i].second -= hs;
          else
            edges[i].second -= gs;
      }
    }
  }
  cout << cnt;
}
