#include <bits/stdc++.h>
using namespace std;
int N, M;
int X[100000];
int U[100000], R[100000];
long long T[100000];
int MX[100000];
int find(int x) {
  if (U[x] == x) return x;
  return U[x] = find(U[x]);
}
void unite(int x, int y) {
  x = find(x), y = find(y);
  if (x == y) return;
  if (R[x] < R[y]) swap(x, y);
  U[y] = x;
  R[x] += R[y];
  R[y] = 0;
  T[x] += T[y];
  T[y] = 0;
  MX[x] = max(MX[x], MX[y]);
}
bool f(int x) {
  x = find(x);
  return T[x] >= MX[x];
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  for (int i = 0; i < (N); i++) cin >> X[i];
  vector<pair<int, pair<int, int> > > edges;
  for (int i = 0; i < (M); i++) {
    int a, b, y;
    cin >> a >> b >> y;
    a--, b--;
    edges.push_back(make_pair(y, pair<int, int>(a, b)));
  }
  sort((edges).begin(), (edges).end());
  int m = 0;
  int unstable = 0;
  for (int i = 0; i < (N); i++) U[i] = i, R[i] = 1, T[i] = X[i];
  for (int i = 0; i < (M); i++) {
    int a = edges[i].second.first, b = edges[i].second.second,
        y = edges[i].first;
    if (find(a) != find(b)) {
      if (!f(a)) unstable--;
      if (!f(b)) unstable--;
      unite(a, b);
    }
    MX[find(a)] = max(MX[find(a)], y);
    if (!f(b)) unstable++;
    if (unstable == 0) m = i + 1;
  }
  cout << M - m << "\n";
  return 0;
}
