#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T1, class T2>
ostream& operator<<(ostream& s, pair<T1, T2> P) {
  return s << '<' << P.first << ", " << P.second << '>';
}
template <class T>
ostream& operator<<(ostream& s, vector<T> P) {
  for (int i = 0; i < P.size(); ++i) {
    if (i > 0) {
      s << " ";
    }
    s << P[i];
  }
  return s;
}
template <class T>
ostream& operator<<(ostream& s, vector<vector<T> > P) {
  for (int i = 0; i < P.size(); ++i) {
    s << endl << P[i];
  }
  return s << endl;
}
template <class T>
ostream& operator<<(ostream& s, set<T> P) {
  for (__typeof__((P).begin()) it = (P).begin(); it != (P).end(); ++it) {
    s << "<" << *it << "> ";
  }
  return s << endl;
}
template <class T1, class T2>
ostream& operator<<(ostream& s, map<T1, T2> P) {
  for (__typeof__((P).begin()) it = (P).begin(); it != (P).end(); ++it) {
    s << "<" << it->first << "->" << it->second << "> ";
  }
  return s << endl;
}
struct UnionFind {
  vector<int> par;
  vector<long long> w;
  UnionFind(int n, vector<long long> w) : par(n, -1), w(w) {}
  void init(int n) { par.assign(n, -1); }
  int root(int x) {
    if (par[x] < 0)
      return x;
    else
      return par[x] = root(par[x]);
  }
  bool issame(int x, int y) { return root(x) == root(y); }
  bool merge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
    w[x] += w[y];
    return true;
  }
  long long get(int x) {
    x = root(x);
    return w[x];
  }
  int size(int x) { return -par[root(x)]; }
};
ostream& operator<<(ostream& s, UnionFind uf) {
  map<int, vector<int> > res;
  for (int i = 0; i < uf.par.size(); ++i) {
    int r = uf.root(i);
    res[r].push_back(i);
  }
  for (map<int, vector<int> >::iterator it = res.begin(); it != res.end();
       ++it) {
    s << endl;
    for (int j = 0; j < (int)it->second.size(); ++j) {
      s << it->second[j] << ", ";
    }
  }
  return s << endl;
}
int N, M;
vector<long long> X;
using pint = pair<int, int>;
using Edge = pair<long long, pint>;
int main() {
  while (cin >> N >> M) {
    X.resize(N);
    vector<Edge> edges;
    for (int i = 0; i < N; ++i) cin >> X[i];
    for (int i = 0; i < M; ++i) {
      int a, b;
      long long w;
      cin >> a >> b >> w;
      --a, --b;
      edges.push_back(Edge(w, pint(a, b)));
    }
    sort(edges.begin(), edges.end());
    vector<int> left(M, 0), right(M, M + 1);
    while (true) {
      map<int, vector<int> > distToQueries;
      bool update = false;
      for (int q = 0; q < M; ++q) {
        if (right[q] - left[q] > 1) {
          update = true;
          int mid = (left[q] + right[q]) / 2;
          distToQueries[mid].push_back(q);
        }
      }
      if (!update) break;
      UnionFind uf(N, X);
      for (auto it = distToQueries.begin(); it != distToQueries.end(); ++it) {
        int mid = (it->first);
        for (int i = 0; i < mid; ++i) {
          int u = edges[i].second.first, v = edges[i].second.second;
          uf.merge(u, v);
        }
        for (auto q : it->second) {
          Edge e = edges[q];
          int u = edges[q].second.first, v = edges[q].second.second;
          if (uf.issame(u, v) && uf.get(edges[q].second.first) >= e.first)
            right[q] = mid;
          else
            left[q] = mid;
        }
      }
    }
    vector<vector<int> > G(M);
    queue<int> que;
    vector<int> dist(M, -1);
    for (int i = 0; i < M; ++i) {
      if (right[i] == M + 1)
        que.push(i), dist[i] = 0;
      else
        G[right[i] - 1].push_back(i);
    }
    int res = que.size();
    while (!que.empty()) {
      int v = que.front();
      que.pop();
      for (auto nv : G[v]) {
        if (dist[nv] == -1) {
          dist[nv] = dist[v] + 1;
          que.push(nv);
          ++res;
        }
      }
    }
    cout << res << endl;
  }
}
