#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void YES(T condition) {
  if (condition)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
template <class T>
inline void Yes(T condition) {
  if (condition)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
template <class T>
inline void POSS(T condition) {
  if (condition)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}
template <class T>
inline void Poss(T condition) {
  if (condition)
    cout << "Possible" << endl;
  else
    cout << "Impossible" << endl;
}
template <class T>
inline void First(T condition) {
  if (condition)
    cout << "First" << endl;
  else
    cout << "Second" << endl;
}
template <class T = string, class U = char>
int character_count(T text, U character) {
  int ans = 0;
  for (U i : text) {
    ans += (i == character);
  }
  return ans;
}
long power(long base, long exponent, long module) {
  if (exponent % 2) {
    return power(base, exponent - 1, module) * base % module;
  } else if (exponent) {
    long root_ans = power(base, exponent / 2, module);
    return root_ans * root_ans % module;
  } else {
    return 1;
  }
}
struct position {
  int y, x;
};
position mv[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
template <class T, class U>
string to_string(pair<T, U> x) {
  return to_string(x.first) + "," + to_string(x.second);
}
template <class itr>
void array_output(itr start, itr goal) {
  string ans;
  for (auto i = start; i != goal; i++) {
    ans += to_string(*i) + " ";
  }
  ans.pop_back();
  cout << ans << endl;
}
template <class itr>
void cins(itr start, itr goal) {
  for (auto i = start; i != goal; i++) {
    cin >> (*i);
  }
}
template <class T>
T gcd(T a, T b) {
  if (a && b) {
    return gcd(min(a, b), max(a, b) % min(a, b));
  } else {
    return a;
  }
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
struct combination {
  vector<long> fact, inv;
  combination(int sz) : fact(sz + 1), inv(sz + 1) {
    fact[0] = 1;
    for (int i = 1; i <= sz; i++) {
      fact[i] = fact[i - 1] * i % (long)(1e9 + 7);
    }
    inv[sz] = power(fact[sz], (long)(1e9 + 7) - 2, (long)(1e9 + 7));
    for (int i = sz - 1; i >= 0; i--) {
      inv[i] = inv[i + 1] * (i + 1) % (long)(1e9 + 7);
    }
  }
  long C(int p, int q) const {
    if (q < 0 || p < q) return 0;
    return (fact[p] * inv[q] % (long)(1e9 + 7) * inv[p - q] % (long)(1e9 + 7));
  }
};
vector<long> X;
struct PartiallyPersistentUnionFind {
  vector<long> data;
  vector<long> data2;
  vector<long> last;
  vector<vector<pair<long, long>>> add;
  vector<vector<pair<long, long>>> add2;
  PartiallyPersistentUnionFind() {}
  PartiallyPersistentUnionFind(long sz)
      : data(sz, -1l), last(sz, 1111100000l), add(sz), add2(sz) {
    for (auto &vs : add) vs.emplace_back(-1l, -1l);
    for (int i = 0; i < sz; i++) add2[i].push_back({-1l, -X[i]});
    for (int i = 0; i < sz; i++) data2.push_back(-X[i]);
  }
  bool unite(long t, long x, long y) {
    x = find(t, x);
    y = find(t, y);
    if (x == y) return false;
    if (data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data2[x] += data2[y];
    add[x].emplace_back(t, data[x]);
    add2[x].emplace_back(t, data2[x]);
    data[y] = x;
    last[y] = t;
    return true;
  }
  long find(long t, long x) {
    if (t < last[x]) return x;
    return find(t, data[x]);
  }
  long size(long t, long x) {
    x = find(t, x);
    return -prev(lower_bound(begin(add[x]), end(add[x]), make_pair(t, 0l)))
                ->second;
  }
  long size2(long t, long x) {
    x = find(t, x);
    return -prev(lower_bound(begin(add2[x]), end(add2[x]), make_pair(t, 0l)))
                ->second;
  }
};
struct UnionFind {
  vector<int> data;
  UnionFind(int sz) { data.assign(sz, -1); }
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return (false);
    if (data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
  int find(int k) {
    if (data[k] < 0) return (k);
    return find(data[k]);
  }
  int size(int k) { return (-data[find(k)]); }
};
UnionFind graph2(1);
long limit = 2e9;
vector<vector<pair<int, long>>> roads_x;
vector<bool> came;
void dfs(int now) {
  came[now] = true;
  for (auto i : roads_x[now]) {
    if (i.second <= limit && !came[i.first]) {
      dfs(i.first);
    }
  }
}
int main() {
  int N, M;
  cin >> N >> M;
  X.resize(N);
  cins((X).begin(), (X).end());
  pair<long, pair<int, int>> roads[M];
  roads_x.resize(N);
  for (int i = 0; i < M; i++) {
    cin >> roads[i].second.first >> roads[i].second.second >> roads[i].first;
    roads_x[roads[i].second.first - 1].push_back(
        {roads[i].second.second - 1, roads[i].first});
  }
  sort(roads, roads + M);
  PartiallyPersistentUnionFind graph(N);
  for (int i = 0; i < M; i++) {
    graph.unite(roads[i].first, roads[i].second.first - 1,
                roads[i].second.second - 1);
  }
  reverse(roads, roads + M);
  came.resize(N, false);
  int ans = 0;
  for (int i = 0; i < M; i++) {
    limit = roads[i].first;
    if (came[roads[i].second.first - 1] && came[roads[i].second.second - 1]) {
      ans++;
      continue;
    }
    graph2.unite(roads[i].second.first - 1, roads[i].second.second - 1);
    if (graph.size2(roads[i].first, roads[i].second.first - 1) >=
        roads[i].first) {
      dfs(roads[i].second.first - 1);
      ans++;
    }
  }
  cout << ans << endl;
}
