#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long>> g[100010];
long long t = 0;
bool cmp(pair<pair<long long, long long>, long long> aa,
         pair<pair<long long, long long>, long long> bb) {
  return aa.second < bb.second;
}
struct node {
  long long mxedge, cntedge, weight, pr, siz;
};
struct comp {
  vector<pair<long long, long long>> ver;
  vector<pair<pair<long long, long long>, long long>> edge;
  vector<node> pred;
  void build() {
    map<long long, long long> ma;
    pred.resize((long long)ver.size() + 2);
    for (long long i = 0; i < (long long)ver.size(); i++) {
      ma[ver[i].first] = i;
      pred[i].mxedge = 0;
      pred[i].cntedge = 0;
      pred[i].pr = i;
      pred[i].weight = ver[i].second;
      pred[i].siz = 0;
    }
    for (long long i = 0; i < (long long)edge.size(); i++) {
      edge[i].first.first = ma[edge[i].first.first];
      edge[i].first.second = ma[edge[i].first.second];
    }
    sort(edge.begin(), edge.end(), cmp);
  }
  long long fans = 0;
  long long get(long long x) {
    while (pred[x].pr != x) x = pred[x].pr;
    return x;
  }
  bool f;
  void un2(long long x, long long y, long long h) {
    x = get(x);
    y = get(y);
    if (x == y) {
      pred[x].mxedge = h;
      pred[x].cntedge++;
      if (pred[x].mxedge <= pred[x].weight) fans++;
      return;
    }
    if (pred[x].siz == pred[y].siz) {
      pred[x].siz++;
    }
    if (pred[x].mxedge <= pred[x].weight) {
      fans -= pred[x].cntedge;
    }
    if (pred[y].mxedge <= pred[y].weight) {
      fans -= pred[y].cntedge;
    }
    if (pred[x].siz > pred[y].siz) {
      pred[y].pr = x;
      pred[x].cntedge += pred[y].cntedge + 1;
      pred[x].weight += pred[y].weight;
      pred[x].mxedge = h;
      if (pred[x].mxedge <= pred[x].weight) fans += pred[x].cntedge;
    } else {
      pred[x].pr = y;
      pred[y].cntedge += pred[x].cntedge + 1;
      pred[y].weight += pred[x].weight;
      pred[y].mxedge = h;
      if (pred[y].mxedge <= pred[y].weight) fans += pred[y].cntedge;
    }
  }
  void un(long long x, long long y, long long h) {
    x = get(x);
    y = get(y);
    if (pred[x].weight + pred[y].weight < h) {
      return;
    }
    if (x == y) {
      pred[x].mxedge = h;
      pred[x].cntedge++;
      if (pred[x].mxedge <= pred[x].weight) fans++;
      return;
    }
    f = true;
    if (pred[x].siz == pred[y].siz) {
      pred[x].siz++;
    }
    if (pred[x].mxedge <= pred[x].weight) {
      fans -= pred[x].cntedge;
    }
    if (pred[y].mxedge <= pred[y].weight) {
      fans -= pred[y].cntedge;
    }
    if (pred[x].siz > pred[y].siz) {
      pred[y].pr = x;
      pred[x].cntedge += pred[y].cntedge + 1;
      pred[x].weight += pred[y].weight;
      pred[x].mxedge = h;
      if (pred[x].mxedge <= pred[x].weight) fans += pred[x].cntedge;
    } else {
      pred[x].pr = y;
      pred[y].cntedge += pred[x].cntedge + 1;
      pred[y].weight += pred[x].weight;
      pred[y].mxedge = h;
      if (pred[y].mxedge <= pred[y].weight) fans += pred[y].cntedge;
    }
  }
  long long getans() {
    vector<pair<pair<long long, long long>, long long>> gl;
    long long mx = 0;
    for (long long i = 0; i < (long long)edge.size(); i++) {
      f = false;
      un(edge[i].first.first, edge[i].first.second, edge[i].second);
      if (!f) {
        gl.push_back(edge[i]);
      }
      mx = max(mx, fans);
    }
    for (long long i = 0; i < (long long)gl.size(); i++) {
      un2(gl[i].first.first, gl[i].first.second, gl[i].second);
      mx = max(mx, fans);
    }
    return mx;
  }
};
comp ar[100010];
long long a[100010];
long long used[100010];
set<pair<long long, long long>> s;
void dfs(long long v) {
  used[v] = 1;
  ar[t].ver.push_back({v, a[v]});
  for (auto u : g[v]) {
    if (s.count({min(v, u.first), max(v, u.first)}) == 0) {
      ar[t].edge.push_back({{v, u.first}, u.second});
      s.insert({min(v, u.first), max(v, u.first)});
    }
    if (used[u.first] != 0) continue;
    dfs(u.first);
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
  }
  long long x, y, z;
  for (long long i = 0; i < m; ++i) {
    cin >> x >> y >> z;
    g[x - 1].push_back({y - 1, z});
    g[y - 1].push_back({x - 1, z});
  }
  for (long long i = 0; i < n; i++) {
    if (used[i] == 0) {
      s.clear();
      dfs(i);
      t++;
    }
  }
  long long pans = 0;
  for (long long i = 0; i < t; i++) {
    ar[i].build();
    pans = ar[i].getans();
  }
  cout << m - pans << endl;
  return 0;
}
