#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
  fill((T*)array, (T*)(array + N), val);
}
const int inf = 0x3fffffff;
const long long int INF = 0x3fffffffffffffff;
int n, m;
long long int x[100010];
int p[100010], comp[100010];
struct edge {
  int u, v, w;
  bool operator<(const edge& e) const { return w < e.w; }
};
vector<edge> es;
int root(int v) { return p[v] == v ? v : root(p[v]); }
int main() {
  scanf("%d%d", &n, &m);
  es.resize(m);
  Fill(comp, 0);
  for (int i = (0); i < (n); i++) p[i] = i, scanf("%d", &x[i]);
  for (int i = (0); i < (m); i++)
    scanf("%d%d%d", &es[i].u, &es[i].v, &es[i].w), es[i].u--, es[i].v--;
  sort((es).begin(), (es).end());
  int ans = 0, sub = 0;
  for (int i = (0); i < (m); i++) {
    int u = root(es[i].u), v = root(es[i].v);
    if (u == v) {
      if (x[u] >= es[i].w)
        sub++;
      else
        comp[v]++;
    } else {
      p[u] = v;
      x[v] += x[u];
      if (x[v] >= es[i].w)
        sub += comp[u] + comp[v] + 1, comp[v] = 0;
      else
        comp[v] += comp[u] + 1;
    }
    chmax(ans, sub);
  }
  printf("%d\n", m - ans);
  return 0;
}
