 #include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
const int N = 2e5 + 10;
struct node
{
    long long all_v;
    int edges, ans_edges, max_edge;
    int fa;
}f[N];
struct edge{
    int x, y, v;
}a[N];
int n, m;
bool cmp(const edge &a, const edge &b)
{
    return a.v < b.v;
}
int getfa(int x)
{
    if (f[x].fa == x) return x;
    return f[x].fa = getfa(f[x].fa);
}
int main()
{
    scanf("%d %d", &n ,&m);
    for (int i = 1 ; i <= n; i ++)
        scanf("%lld", &f[i].all_v), f[i].fa = i;
    for (int i = 1 ; i <= m; i ++)
        scanf("%d %d %d", &a[i].x ,&a[i].y, &a[i].v);
    sort(a + 1, a + m + 1, cmp);
    for (int i = 1; i <= m ; i ++)
    {
        int fax = getfa(a[i].x);
        int fay = getfa(a[i].y);
        if (fax == fay)
        {
            f[fax].edges ++;
            f[fax].max_edge = a[i].v;
            if (f[fax].all_v >= a[i].v)
                f[fax].ans_edges = f[fax].edges;
        } else{
            f[fax].fa = fay;
            f[fay].ans_edges += f[fax].ans_edges;
            f[fay].all_v += f[fax].all_v;
            f[fay].max_edge = a[i].v;
            f[fay].edges += 1 + f[fax].edges;
            if (f[fay].all_v >= a[i].v)
                f[fay].ans_edges = f[fay].edges;
        }
    }
    printf("%d\n", m - f[getfa(1)].ans_edges);
    return 0;
}