#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B>
bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
long long inf = sizeof(long long) == sizeof(long long) ? 2e18 : 1e9 + 10;
vector<long long> x;
struct UnionFind {
  vector<long long> data;
  vector<long long> num;
  vector<long long> ma;
  UnionFind(long long size) {
    data = vector<long long>(size, -1);
    num = x;
    ma = vector<long long>(size);
  }
  bool unionSet(long long x, long long y, long long z) {
    x = root(x);
    y = root(y);
    cmax(ma[x], z);
    if (x == y) return 0;
    if (data[y] < data[x]) swap(x, y);
    data[x] += data[y], data[y] = x;
    num[x] += num[y];
    num[y] = 0;
    cmax(ma[x], ma[y]);
    ma[y] = 0;
    cmax(ma[x], z);
    return 1;
  }
  bool findSet(long long x, long long y) { return root(x) == root(y); }
  long long root(long long x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  long long size(long long x) { return -data[root(x)]; }
};
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  x = vector<long long>(n);
  for (long long i = 0; i < n; i++) cin >> x[i];
  vector<vector<long long> > in(m, vector<long long>(3));
  for (long long i = 0; i < m; i++) cin >> in[i][1] >> in[i][2] >> in[i][0];
  for (long long i = 0; i < m; i++) in[i][1]--, in[i][2]--;
  sort(in.begin(), in.end());
  vector<vector<long long> > d(n, {0, 1000000010});
  for (long long i = 0; i < 32; i++) {
    vector<vector<long long> > h;
    for (long long j = 0; j < n; j++) h.push_back({(d[j][0] + d[j][1]) / 2, j});
    sort(h.begin(), h.end());
    UnionFind uf(n);
    long long it = 0;
    for (long long j = 0; j < n; j++) {
      while (it < m && h[j][0] >= in[it][0]) {
        uf.unionSet(in[it][1], in[it][2], in[it][0]);
        it++;
      }
      long long t = uf.root(h[j][1]);
      if (uf.num[t] < uf.ma[t])
        d[h[j][1]][1] = h[j][0];
      else
        d[h[j][1]][0] = h[j][0];
    }
  }
  long long out = 0;
  for (long long i = m - 1; i >= 0; i--) {
    long long a = in[i][1], b = in[i][2], c = in[i][0];
    long long t = max(d[a][0], d[b][0]);
    if (c > t)
      out++;
    else {
      d[a][0] = d[b][0] = t;
    }
  }
  cout << out << endl;
}
