#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
const long long int mod = 1000000007;
const long long int big = 2.19e18 + 1;
const long double pai = 3.141592653589793238462643383279502884197;
const long double eps = 1e-15;
template <class T, class U>
bool mineq(T& a, U b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T, class U>
bool maxeq(T& a, U b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
long long int gcd(long long int a, long long int b) {
  if (a % b == 0) {
    return b;
  } else
    return gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
  if (a == 0) {
    return b;
  }
  return a / gcd(a, b) * b;
}
template <class T>
void SO(T& ve) {
  sort(ve.begin(), ve.end());
}
template <class T>
void REV(T& ve) {
  reverse(ve.begin(), ve.end());
}
template <class T>
long long int LBI(vector<T>& ar, T in) {
  return lower_bound(ar.begin(), ar.end(), in) - ar.begin();
}
template <class T>
long long int UBI(vector<T>& ar, T in) {
  return upper_bound(ar.begin(), ar.end(), in) - ar.begin();
}
vector<vector<pair<int, long long int>>> go;
vector<long long int> saigo;
void dfs(int ter, int per, long long int suu) {
  saigo[ter] = suu;
  for (auto it : go[ter]) {
    if (it.first == per || it.second > suu) {
      continue;
    }
    dfs(it.first, ter, suu);
  }
}
int main(void) {
  int n, m, i, ans = 0;
  cin >> n >> m;
  vector<long long int> X(n);
  for (i = 0; i < n; i++) {
    cin >> X[i];
  }
  vector<tuple<long long int, int, int, long long int>> hen(m);
  for (i = 0; i < m; i++) {
    int a, b;
    long long int y;
    cin >> a >> b >> y;
    a--;
    b--;
    hen[i] = make_tuple(y, a, b, 0LL);
  }
  SO(hen);
  vector<int> uni(n);
  for (i = 0; i < n; i++) {
    uni[i] = i;
  }
  vector<int> ran(n);
  vector<long long int> owa = X;
  go.resize(n);
  saigo.resize(n);
  vector<tuple<long long int, int, int, long long int>> zen;
  vector<tuple<long long int, int, int, long long int>> ato;
  for (i = 0; i < m; i++) {
    int a, b;
    long long int y;
    long long int gm;
    tie(y, a, b, gm) = hen[i];
    int aa = a, bb = b;
    while (a != uni[a]) {
      a = uni[a];
    }
    while (b != uni[b]) {
      b = uni[b];
    }
    if (a == b) {
      ato.push_back(hen[i]);
      continue;
    }
    if (ran[a] < ran[b]) {
      swap(a, b);
    }
    if (ran[a] == ran[b]) {
      ran[a]++;
    }
    owa[a] += owa[b];
    if (owa[a] >= y) {
      get<3>(hen[i]) = owa[a];
    }
    uni[b] = a;
    zen.push_back(hen[i]);
    go[aa].push_back(make_pair(bb, y));
    go[bb].push_back(make_pair(aa, y));
  }
  REV(zen);
  for (i = 0; i < n - 1; i++) {
    int a, b;
    long long int y;
    long long int ok;
    tie(y, a, b, ok) = zen[i];
    if (saigo[a] != 0) {
      continue;
    }
    if (ok) {
      dfs(a, -1, y);
      continue;
    }
    ans++;
  }
  for (i = 0; i < n; i++) {
    maxeq(saigo[i], X[i]);
  }
  for (i = 0; i < ato.size(); i++) {
    int a, b;
    long long int y;
    long long int ok;
    tie(y, a, b, ok) = ato[i];
    if (y > min(saigo[a], saigo[b])) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
