#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn = 100005;

int n,m;
int a[maxn];
struct P{
  int x,y,v;
  bool operator<(const P&a)const {
    return v<a.v;
  }
}p[maxn];
vector<int>e[maxn];

int f[maxn];
ll sum[maxn];
int pd(int x){
  if(f[x]!=x)f[x]=pd(f[x]);
  return f[x];
}
bool can[maxn], vis[maxn];

void dfs(int x,int lim){
  vis[x]=true;
  for(int i=0;i<e[x].size();i++){
    int idx = e[x][i];
    if(p[idx].v>lim)continue;
    if(!vis[p[idx].x])dfs(p[idx].x, lim);
    if(!vis[p[idx].y])dfs(p[idx].y, lim);
  }
}

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
#endif
  cin>>n>>m;
  for(int i=1;i<=n;i++)cin>>a[i];
  for(int i=1;i<=m;i++){
    cin>>p[i].x>>p[i].y>>p[i].v;
  }
  sort(p+1,p+m+1);
  for(int i=1;i<=m;i++){
    e[p[i].x].push_back(i);
    e[p[i].y].push_back(i);
  }
  for(int i=1;i<=n;i++){
    f[i]=i;
    sum[i]=a[i];
    vis[i]=false;
  }
  for(int i=1;i<=m;i++){
    can[i]=false;
    int px = pd(p[i].x);
    int py = pd(p[i].y);
    if(px!=py){
      f[px]=py;
      sum[py]+=sum[px];
      sum[px]=0;
    }
    if(sum[py]>=p[i].v){
      can[i]=true;
    }
  }
  int ret = 0;
  for(int i=m;i>=1;i--){
    if(vis[p[i].x])continue;
    if(!can[i]){
      ret++;
      continue;
    }
    dfs(p[i].x, p[i].v);
  }
  cout<<ret<<endl;
  return 0;
}