#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}
template <typename T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
class union_find {
 private:
  vector<int> parent, rank, gs;
  int size;

 public:
  int count_group;
  union_find() = default;
  union_find(int n) { init(n); }
  void init(int n) {
    size = n;
    count_group = n;
    parent.resize(size);
    rank.assign(size, 0);
    gs.assign(size, 1);
    for (int i = 0; i < size; ++i) parent[i] = i;
  }
  int find(int x) {
    if (parent[x] == x)
      return x;
    else
      return parent[x] = find(parent[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
      parent[x] = y;
      gs[y] += gs[x];
    } else {
      parent[y] = x;
      gs[x] += gs[y];
      if (rank[x] == rank[y]) ++rank[x];
    }
    --count_group;
  }
  bool is_same_group(int x, int y) { return find(x) == find(y); }
  int group_size(int x) { return gs[find(x)]; };
};
void solve() {
  i64 N, M;
  cin >> N >> M;
  vector<i64> X(N);
  for (i64 i = i64(0), i_max_for_repmacro = i64(N); i < i_max_for_repmacro; ++i)
    cin >> X[i];
  vector<i64> A(M), B(M), Y(M);
  for (i64 i = i64(0), i_max_for_repmacro = i64(M); i < i_max_for_repmacro;
       ++i) {
    cin >> A[i] >> B[i] >> Y[i];
    --A[i];
    --B[i];
  }
  using tup = tuple<i64, i64, i64>;
  using pq = priority_queue<tup, vector<tup>, greater<tup>>;
  union_find uf(N);
  vector<i64> sum(N), maxe(N);
  pq undecided, hold_diff;
  vector<pq> hold_same(N);
  set<i64> ok, no;
  i64 cnt = 0, ans = 0;
  for (i64 i = i64(0), i_max_for_repmacro = i64(N); i < i_max_for_repmacro;
       ++i) {
    sum[i] = X[i];
    ok.insert(i);
  }
  for (i64 i = i64(0), i_max_for_repmacro = i64(M); i < i_max_for_repmacro;
       ++i) {
    undecided.emplace(make_tuple(Y[i], A[i], B[i]));
  }
  while (true) {
    if (!undecided.empty()) {
      auto e = undecided.top();
      undecided.pop();
      i64 c, u, v;
      tie(c, u, v) = e;
      u = uf.find(u);
      v = uf.find(v);
      if (u == v) {
        if (sum[u] >= c) {
          ++cnt;
          chmax(maxe[u], c);
          if (no.size() == 0) chmax(ans, cnt);
        } else {
          hold_same[u].push(make_tuple(c, u, v));
        }
      } else {
        if (sum[u] + sum[v] >= c) {
          ++cnt;
          uf.unite(u, v);
          if (v == uf.find(u)) swap(u, v);
          ok.erase(v);
          no.erase(v);
          sum[u] += sum[v];
          chmax(maxe[u], maxe[v]);
          chmax(maxe[u], c);
          if (sum[u] >= maxe[u]) {
            no.erase(u);
            ok.insert(u);
          }
          if (no.size() == 0) chmax(ans, cnt);
          while (!hold_same[v].empty()) {
            auto e = hold_same[v].top();
            hold_same[v].pop();
            hold_same[u].push(e);
          }
          while (!hold_same[u].empty()) {
            auto c2 = get<0>(hold_same[u].top());
            if (c2 > sum[u]) break;
            hold_same[u].pop();
            ++cnt;
            chmax(maxe[u], c2);
            if (no.size() == 0) chmax(ans, cnt);
          }
        } else {
          hold_diff.push(make_tuple(c, u, v));
        }
      }
      continue;
    }
    if (!hold_diff.empty()) {
      i64 c, u, v;
      tie(c, u, v) = hold_diff.top();
      hold_diff.pop();
      u = uf.find(u);
      v = uf.find(v);
      if (u == v) {
        if (sum[u] >= c) {
          ++cnt;
          chmax(maxe[u], c);
          if (sum[u] >= maxe[u]) {
            no.erase(u);
            ok.insert(u);
          }
          if (no.size() == 0) chmax(ans, cnt);
        } else {
          hold_same[u].push(make_tuple(c, u, v));
        }
        continue;
      }
      uf.unite(u, v);
      ++cnt;
      if (v == uf.find(u)) swap(u, v);
      ok.erase(v);
      no.erase(v);
      sum[u] += sum[v];
      chmax(maxe[u], maxe[v]);
      chmax(maxe[u], c);
      if (sum[u] >= maxe[u]) {
        no.erase(u);
        ok.insert(u);
      } else {
        ok.erase(u);
        no.insert(u);
      }
      if (no.size() == 0) chmax(ans, cnt);
      while (!hold_same[v].empty()) {
        auto e = hold_same[v].top();
        hold_same[v].pop();
        hold_same[u].push(e);
      }
      while (!hold_same[u].empty()) {
        auto c2 = get<0>(hold_same[u].top());
        if (c2 > sum[u]) break;
        hold_same[u].pop();
        ++cnt;
        chmax(maxe[u], c2);
        if (no.size() == 0) chmax(ans, cnt);
      }
      continue;
    }
    break;
  }
  cout << M - ans << endl;
}
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(16);
  solve();
  return 0;
}
