#include <bits/stdc++.h>
using namespace std;
struct BoolName : numpunct<char> {
  string t, f;
  BoolName(string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const { return t; }
  string do_falsename() const { return f; }
};
struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;
template <typename T>
istream& operator>>(istream& s, vector<T>& v) {
  for (T& t : v) s >> t;
  return s;
}
template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  for (const T& t : v) s << t << endl;
  return s;
}
void set_bool_name(string t, string f) {
  cout.imbue(locale(cout.getloc(), new BoolName(t, f)));
}
template <typename T>
bool chmin(T& a, T b) {
  return a > b ? a = b, true : false;
}
template <typename T>
bool chmax(T& a, T b) {
  return a < b ? a = b, true : false;
}
template <typename T>
void sort(vector<T>& v) {
  sort(v.begin(), v.end());
}
template <typename T>
T min(const vector<T>& v) {
  return *min_element(v.begin(), v.end());
}
template <typename T>
T max(const vector<T>& v) {
  return *max_element(v.begin(), v.end());
}
template <typename T>
int min_element(vector<T>& v) {
  return min_element(v.begin(), v.end()) - v.begin();
}
template <typename T>
int max_element(vector<T>& v) {
  return max_element(v.begin(), v.end()) - v.begin();
}
template <typename T, typename Function>
void sort(vector<T>& v, Function func) {
  sort(v.begin(), v.end(), func);
}
template <typename T>
void rsort(vector<T>& v) {
  sort(v.rbegin(), v.rend());
}
template <typename T>
void reverse(vector<T>& v) {
  reverse(v.begin(), v.end());
}
template <typename T>
void unique(vector<T>& v) {
  v.erase(unique(v.begin(), v.end()), v.end());
}
template <typename T>
void nth_element(vector<T>& v, int n) {
  nth_element(v.begin(), v.begin() + n, v.end());
}
template <typename T>
bool next_permutation(vector<T>& v) {
  return next_permutation(v.begin(), v.end());
}
template <typename T>
int find(vector<T>& v, T t) {
  return find(v.begin(), v.end(), t) - v.begin();
}
template <typename T, typename S>
int in(T v, S t) {
  return find(v.begin(), v.end(), t) != v.end();
}
template <typename T>
int lower_bound(vector<T>& v, T t) {
  return lower_bound(v.begin(), v.end(), t) - v.begin();
}
template <typename T>
int upper_bound(vector<T>& v, T t) {
  return upper_bound(v.begin(), v.end(), t) - v.begin();
}
template <typename T, typename S = typename T::value_type,
          typename BinaryOperation>
S accumulate(const T& v, S init, BinaryOperation func) {
  return accumulate(v.begin(), v.end(), init, func);
}
template <typename T, typename S = typename T::value_type>
S accumulate(const T& v, S init = 0) {
  return accumulate(v.begin(), v.end(), init);
}
template <typename T>
void adjacent_difference(vector<T>& v) {
  adjacent_difference(v.begin(), v.end(), v.begin());
}
template <typename T>
void adjacent_difference(vector<T>& v, vector<T>& u) {
  adjacent_difference(v.begin(), v.end(), u.begin());
}
template <typename T>
vector<T> partial_sum(const vector<T>& v) {
  vector<T> u(v.size());
  partial_sum(v.begin(), v.end(), u.begin());
  return u;
}
template <typename T>
T inner_product(vector<T>& v, vector<T>& u) {
  return inner_product(v.begin(), v.end(), u.begin(), T(0));
}
template <typename T>
int count(const T& v, typename T::value_type t) {
  return count(v.begin(), v.end(), t);
}
template <typename T, typename Function>
int count_if(const vector<T>& v, Function func) {
  return count_if(v.begin(), v.end(), func);
}
template <typename T, typename Function>
void remove_if(vector<T>& v, Function func) {
  v.erase(remove_if(v.begin(), v.end(), func), v.end());
}
template <typename T, typename Function>
bool all_of(vector<T> v, Function func) {
  return all_of(v.begin(), v.end(), func);
}
template <typename T, typename Function>
bool any_of(vector<T> v, Function func) {
  return any_of(v.begin(), v.end(), func);
}
template <typename T, typename Function>
bool none_of(vector<T> v, Function func) {
  return none_of(v.begin(), v.end(), func);
}
template <typename T>
vector<T> subvector(vector<T>& v, int a, int b) {
  return vector<T>(v.begin() + a, v.begin() + b);
}
template <typename T>
int kinds(const T& v) {
  return set<typename T::value_type>(v.begin(), v.end()).size();
}
template <typename T>
map<typename T::value_type, int> count_kinds(const T& v) {
  map<typename T::value_type, int> res;
  for (const auto& i : v) ++res[i];
  return res;
}
template <typename T>
void iota(vector<T>& v, T t = 0) {
  iota(v.begin(), v.end(), t);
}
template <typename T>
bool is_sorted(const vector<T>& v) {
  return is_sorted(v.begin(), v.end());
}
class UnionFind {
 private:
  int n;
  vector<int> a;

 public:
  UnionFind(int n) : n(n), a(n, -1) {}
  int find(int x) { return a[x] < 0 ? x : (a[x] = find(a[x])); }
  bool equal(int x, int y) { return find(x) == find(y); }
  void unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return;
    if (a[x] > a[y]) swap(x, y);
    a[x] += a[y];
    a[y] = x;
    --n;
  }
  int size() { return n; }
  int size(int x) { return -a[find(x)]; }
  bool isRoot(int x) { return find(x) == x; }
  vector<vector<int>> groups() {
    vector<vector<int>> r(a.size()), res;
    for (unsigned i = 0; i < a.size(); ++i) r[find(i)].emplace_back(i);
    for (auto&& i : r)
      if (!i.empty()) res.emplace_back(move(i));
    return res;
  }
};
class WeightedUnionFind {
 private:
  int n;
  vector<int> a;

 public:
  vector<int64_t> weight;
  WeightedUnionFind(int n) : n(n), a(n, -1), weight(n) {}
  int find(int x) { return a[x] < 0 ? x : (a[x] = find(a[x])); }
  bool equal(int x, int y) { return find(x) == find(y); }
  void unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return;
    if (a[x] > a[y]) swap(x, y);
    a[x] += a[y];
    weight[x] += weight[y];
    a[y] = x;
    --n;
  }
  int size() { return n; }
  int size(int x) { return -a[find(x)]; }
  int64_t get_weight(int x) { return weight[find(x)]; }
  bool isRoot(int x) { return find(x) == x; }
  vector<vector<int>> groups() {
    vector<vector<int>> r(a.size()), res;
    for (unsigned i = 0; i < a.size(); ++i) r[find(i)].emplace_back(i);
    for (auto&& i : r)
      if (!i.empty()) res.emplace_back(move(i));
    return res;
  }
};
template <typename Edge>
struct FullEdge : public Edge {
  int from;
  FullEdge() = default;
  FullEdge(const int from, const Edge& edge) : Edge(edge), from(from) {}
};
struct Edge {
  using CostType = int;
  const static int cost = 1;
  int to;
  Edge(int to = -1) : to(to) {}
  bool isNone() const { return to == -1; }
};
istream& operator>>(istream& s, FullEdge<Edge>& edge) {
  s >> edge.from >> edge.to;
  return s;
}
ostream& operator<<(ostream& s, const FullEdge<Edge>& edge) {
  s << '(' << edge.from << ',' << edge.to << ')';
  return s;
}
template <typename Cost>
struct WeightedEdge : public Edge {
  using CostType = Cost;
  Cost cost;
  WeightedEdge(int to = -1, Cost cost = 0) : Edge(to), cost(cost) {}
};
template <typename Cost>
istream& operator>>(istream& s, FullEdge<WeightedEdge<Cost>>& edge) {
  s >> edge.from >> edge.to >> edge.cost;
  return s;
}
template <typename Cost>
ostream& operator<<(ostream& s, const FullEdge<WeightedEdge<Cost>>& edge) {
  s << '(' << edge.from << ',' << edge.to << ',' << edge.cost << ')';
  return s;
}
template <typename Capacity>
struct ResidualEdge : public Edge {
  using CapacityType = Capacity;
  Capacity cap;
  int rev;
  ResidualEdge(int to = -1, Capacity cap = 0) : Edge(to), cap(cap) {}
  ResidualEdge reverse(int from) const { return ResidualEdge(from, 0); }
};
template <typename Capacity, typename Cost>
struct WeightedResidualEdge : public ResidualEdge<Capacity> {
  Cost cost;
  WeightedResidualEdge(int to = -1, Capacity cap = 0, Cost cost = 0)
      : ResidualEdge<Capacity>(to, cap), cost(cost) {}
  WeightedResidualEdge reverse(int from) const {
    return WeightedResidualEdge(from, 0, -cost);
  }
};
template <typename Edge>
class Graph {
 public:
  using EdgeType = Edge;
  virtual int size() const = 0;
  template <typename... Args>
  void addEdge(int from, int to, Args...) {
    (void)from;
    (void)to;
  }
  template <typename... Args>
  void addUndirectedEdge(int from, int to, Args...) {
    (void)from;
    (void)to;
  }
  vector<FullEdge<Edge>> getAllEdges() const {
    vector<FullEdge<Edge>> res;
    for (int i = 0; i < size(); ++i) {
      for (const auto& edge : getEdges(i)) {
        res.emplace_back(i, edge);
      }
    }
    return res;
  }
  virtual vector<Edge> getEdges(int from) const = 0;
  virtual Edge getEdge(int from, int to) const = 0;
  virtual bool hasEdge(int from, int to) const = 0;
  int getDegree(int v) const { return getEdges(v).size(); }
  vector<int> getIndegree() const {
    vector<int> degree(size());
    for (const auto& edge : getAllEdges()) ++degree[edge.to];
    return degree;
  }
};
template <typename Graph>
Graph readGraph(int n, int m, bool undirected = true, bool one_origin = true) {
  Graph graph(n);
  for (int i = 0; i < m; ++i) {
    FullEdge<typename Graph::EdgeType> edge;
    cin >> edge;
    if (one_origin) {
      --edge.from;
      --edge.to;
    }
    if (undirected)
      graph.addUndirectedEdge(edge);
    else
      graph.addEdge(edge);
  }
  return graph;
}
template <typename Edge>
class AdjacencyList : public Graph<Edge> {
 protected:
  vector<vector<Edge>> graph;

 public:
  using EdgeType = Edge;
  AdjacencyList() = default;
  AdjacencyList(int n) : graph(n) {}
  int size() const { return graph.size(); }
  template <typename... Args>
  void addEdge(int from, int to, Args... args) {
    graph[from].emplace_back(to, args...);
  }
  void addEdge(const FullEdge<Edge>& edge) {
    graph[edge.from].emplace_back(edge);
  }
  template <typename... Args>
  void addUndirectedEdge(int from, int to, Args... args) {
    addEdge(from, to, args...);
    addEdge(to, from, args...);
  }
  void addUndirectedEdge(FullEdge<Edge> edge) {
    graph[edge.from].emplace_back(edge);
    swap(edge.from, edge.to);
    graph[edge.from].emplace_back(edge);
  }
  vector<Edge> getEdges(int from) const { return graph[from]; }
  Edge getEdge(int from, int to) const {
    Edge res;
    for (const auto& edge : graph[from]) {
      if (edge.to == to) res = edge;
    }
    return res;
  }
  bool hasEdge(int from, int to) const {
    for (const auto& edge : graph[from]) {
      if (edge.to == to) return true;
    }
    return false;
  }
  vector<Edge>& operator[](int v) { return graph[v]; }
  const vector<Edge>& operator[](int v) const { return graph[v]; }
};
template <typename Edge>
istream& operator>>(istream& s, AdjacencyList<Edge>& graph) {
  int n, m;
  cin >> n >> m;
  graph = readGraph<AdjacencyList<Edge>>(n, m);
  return s;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> x(n);
  cin >> x;
  vector<tuple<int, int, int>> edge, edge2;
  for (int i = 0; i < m; ++i) {
    int a, b, y;
    cin >> a >> b >> y;
    edge.emplace_back(y, a - 1, b - 1);
  }
  sort(edge);
  UnionFind uf(n);
  vector<vector<int>> tree(n);
  for (int i = 0; i < m; ++i) {
    int a, b, y;
    tie(y, a, b) = edge[i];
    if (!uf.equal(a, b)) {
      uf.unite(a, b);
      tree[a].emplace_back(b);
      tree[b].emplace_back(a);
      edge2.emplace_back(y, a, b);
    }
  }
  rsort(edge2);
  WeightedUnionFind wuf(n);
  for (int i = 0; i < n; ++i) wuf.weight[i] = x[i];
  for (auto e : edge2) {
    int a, b, y;
    tie(y, a, b) = e;
    queue<int> que;
    que.emplace(a);
    que.emplace(b);
    unordered_set<int> used;
    used.emplace(a);
    used.emplace(b);
    int64_t sum = 0;
    while (!que.empty()) {
      int v = que.front();
      que.pop();
      sum += x[v];
      if (sum >= y) break;
      for (int u : tree[v]) {
        if (used.count(u)) continue;
        used.emplace(u);
        que.emplace(u);
      }
    }
    if (sum < y) {
      for (int j = 0; j < int(tree[a].size()); ++j) {
        if (tree[a][j] == b) {
          tree[a][j] = tree[a].back();
          tree[a].pop_back();
        }
      }
      for (int j = 0; j < int(tree[b].size()); ++j) {
        if (tree[b][j] == a) {
          tree[b][j] = tree[a].back();
          tree[b].pop_back();
        }
      }
    } else {
      wuf.unite(a, b);
    }
  }
  int res = 0;
  for (auto e : edge) {
    int a, b, y;
    tie(y, a, b) = e;
    if (!wuf.equal(a, b) || wuf.get_weight(a) < y) ++res;
  }
  cout << res << endl;
}
