#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pii = pair<int, int>;
template <typename T>
using Vec = vector<T>;
template <typename T>
bool in_range(T x, T lb, T ub) {
  return lb <= x && x < ub;
}
template <typename T>
bool in_range(T x, T y, T lb, T ub) {
  return in_range(x, lb, ub) && in_range(y, lb, ub);
}
template <typename T>
void modAdd(T& a, T b, T mod) {
  a = (a + b + mod) % mod;
}
template <typename T>
void modMul(T& a, T b, T mod) {
  a = (a * b) % mod;
}
template <typename T>
void minUpdate(T& a, T b) {
  a = min(a, b);
}
template <typename T>
void maxUpdate(T& a, T b) {
  a = max(a, b);
}
int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
          Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
const double EPS = 1e-9;
const double PI = acos(-1);
struct Edge {
  int u, v;
  lint Y;
  bool operator<(const Edge& obj) const { return Y < obj.Y; }
};
int N, M;
lint X[100005];
vector<Edge> edge;
void solve() {
  sort((edge).begin(), (edge).end());
  vector<int> par(N, -1);
  vector<lint> w(N, -1), ew(N, -1);
  vector<vector<int> > group(N, vector<int>());
  for (int v = 0; v < N; ++v) {
    par[v] = v;
    w[v] = X[v];
    ew[v] = 0;
    group[v] = {v};
  }
  int BORDER_i = 0, violate = 0;
  for (int i = 0; i < M; ++i) {
    Edge e = edge[i];
    int pu = par[e.u];
    int pv = par[e.v];
    if (pu != pv) {
      if (group[pu].size() > group[pv].size()) swap(pu, pv);
      if (ew[pv] > w[pv]) --violate;
      if (ew[pu] > w[pu]) --violate;
      w[pv] += w[pu];
      for (int v : group[pu]) {
        par[v] = pv;
        group[pv].push_back(v);
      }
      ew[pv] = max(ew[pv], ew[pu]);
      ew[pv] = max(ew[pv], e.Y);
      if (ew[pv] > w[pv]) ++violate;
    }
    if (violate == 0) BORDER_i = i + 1;
  }
  for (int v = 0; v < N; ++v) {
    par[v] = v;
    w[v] = X[v];
    ew[v] = 0;
    group[v] = {v};
  }
  for (int i = 0; i < BORDER_i; ++i) {
    Edge e = edge[i];
    int pu = par[e.u];
    int pv = par[e.v];
    if (pu != pv) {
      if (group[pu].size() > group[pv].size()) swap(pu, pv);
      w[pv] += w[pu];
      for (int v : group[pu]) {
        par[v] = pv;
        group[pv].push_back(v);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < M; ++i) {
    Edge e = edge[i];
    int pu = par[e.u];
    int pv = par[e.v];
    if (pu != pv)
      ++ans;
    else {
      if (w[pv] < e.Y) ++ans;
    }
  }
  cout << ans << endl;
}
int main() {
  cin >> N >> M;
  for (int i = 0; i < N; ++i) cin >> X[i];
  for (int i = 0; i < M; ++i) {
    int a, b;
    lint y;
    cin >> a >> b >> y;
    --a;
    --b;
    edge.push_back(Edge{a, b, y});
  }
  solve();
}
