#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
struct ban
{
    int x, y;
    int d;
    ban(){}
    ban(int x, int y, int d)
    {
        this->x = x;
        this->y = y;
        this->d = d;
    }
};
bool operator<(const ban& a, const ban& b)
{
    return a.d < b.d;
}

int n, m;
int a[N];
ban b[N];

int p[N];
int q[N], qv[N];
long long g[N];
int fi(int x)
{
    if (p[x] == x)
        return x;
    return p[x] = fi(p[x]);
}
void kpc(int x, int y)
{
    x = fi(x);
    y = fi(y);
    p[x] = y;
    q[y] += q[x];
    qv[y] += qv[x];
    g[y] += g[x];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    for (int i = 0; i < m; ++i)
        cin >> b[i].x >> b[i].y >> b[i].d;
    sort(b, b + m);
    for (int i = 1; i <= n; ++i)
    {
        p[i] = i;
        g[i] = a[i];
    }
    int ans = 0;
    for (int i = 0; i < m; ++i)
    {
        int x = b[i].x;
        int y = b[i].y;
        int d = b[i].d;
        if (fi(x) == fi(y))
        {
            ++q[fi(x)];
            if (d <= g[fi(x)])
            {
                ++qv[fi(x)];
                ++ans;
            }
        }
        else
        {
            kpc(x, y);
            ++q[fi(x)];
            if (d <= g[fi(x)])
            {
                ans -= qv[fi(x)];
                qv[fi(x)] = q[fi(x)];
                ans += qv[fi(x)];
            }
        }
    }
    cout << m - ans << endl;
    return 0;
}
