#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
void chmin(int64_t& a, int64_t b) { a = min(a, b); }
template <class T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "{";
  for (long long i = 0; i < (long long)v.size(); i++)
    o << (i > 0 ? ", " : "") << v[i];
  o << "}";
  return o;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
long long q, m, n, k, res, tmp, tmp2, tmp3, h, w;
long long a[100001] = {};
deque<pair<long long, long long>> que;
string s;
map<long long, vector<pair<long long, long long>>> kukan;
vector<pair<long long, pair<long long, long long>>> g;
long long dp[200000];
long long flag;
long long ok[100010] = {};
vector<pair<long long, long long>> g2[200000];
class UnionFind {
 private:
  long long n;
  vector<long long> uni;

 public:
  UnionFind(long long _n) {
    n = _n;
    uni.clear();
    uni.resize(n, -1);
    for (long long i = 0; i < n; i++) {
      uni[i] = -a[i];
    }
  }
  long long root(long long x) {
    if (uni[x] < 0) return x;
    return uni[x] = root(uni[x]);
  }
  bool same(long long x, long long y) { return root(x) == root(y); }
  void unite(long long x, long long y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (uni[x] > uni[y]) swap(x, y);
    uni[x] += uni[y];
    uni[y] = x;
  }
  long long getSize(long long x) { return -uni[root(x)]; }
  void print() {
    for (auto x : uni) cout << x << " ";
    cout << endl;
  }
};
void dfs(long long x, long long c) {
  for (long long j = 0; j < g2[x].size(); j++) {
    pair<long long, long long> i = g2[x][j];
    if (i.second <= c) {
      g2[x][j].second = 1LL << 60;
      res += 1;
      dfs(i.first, c);
    }
  }
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (long long i = 0; i < m; i++) {
    cin >> tmp >> tmp2 >> tmp3;
    g.push_back({tmp3, {tmp2 - 1, tmp - 1}});
    g2[tmp2 - 1].push_back({tmp - 1, tmp3});
    g2[tmp - 1].push_back({tmp2 - 1, tmp3});
  }
  UnionFind UF(n);
  sort((g).begin(), (g).end());
  vector<long long> v;
  for (long long i = 0; i < n; i++) {
    pair<long long, pair<long long, long long>> hen = g[i];
    UF.unite(hen.second.first, hen.second.second);
    if (UF.getSize(hen.second.first) >= hen.first) {
      v.push_back(i);
    }
  }
  res = 0;
  reverse((v).begin(), (v).end());
  for (long long k : v) {
    pair<long long, pair<long long, long long>> hen = g[k];
    dfs(hen.second.second, hen.first);
  }
  cout << m - res / 2 << endl;
}
