#include <bits/stdc++.h>
#define X first
#define Y second
#define sz(a) (int)a.size()
#define pb push_back
#define int long long

using namespace std;

vector <pair <int, int>> g[100010];

int t = 0;

bool cmp(pair <pair <int, int>, int> aa, pair <pair <int, int>, int> bb) {
    return aa.Y < bb.Y;
}

struct node {
    int mxedge, cntedge, weight, pr, siz, rez;
};

struct comp {
    vector <pair <int, int>> ver;
    vector <pair <pair <int, int>, int>> edge;
    vector <node> pred;
    void build() {
        map <int, int> ma;
        pred.resize(sz(ver) + 2);
        for (int i = 0; i < sz(ver); i++) {
            ma[ver[i].X] = i;
            pred[i].mxedge = 0;
            pred[i].cntedge = 0;
            pred[i].pr = i;
            pred[i].weight = ver[i].Y;
            pred[i].siz = 0;
            pred[i].rez = 0;
        }
        for (int i = 0; i < sz(edge); i++) {
            edge[i].X.X = ma[edge[i].X.X];
            edge[i].X.Y = ma[edge[i].X.Y];
        }
        sort(edge.begin(), edge.end(), cmp);
    }
    int fans = 0;
    int get(int x) {
        while (pred[x].pr != x)
            x = pred[x].pr;
        return x;
    }
    void un(int x, int y, int 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++;
        }
        int kk = 0;
        if (pred[x].mxedge <= pred[x].weight) {
            fans -= pred[x].cntedge;
            kk += pred[x].cntedge;
        }
        if (pred[y].mxedge <= pred[y].weight) {
            fans -= pred[y].cntedge;
            kk += 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;
                fans -= pred[x].rez;
                fans -= pred[y].rez;
                pred[x].rez = 0;
            } else {
                fans += kk;
                pred[x].rez += kk + pred[y].rez;
            }
        } 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;
                fans -= pred[x].rez;
                fans -= pred[y].rez;
                pred[y].rez = 0;
            } else {
                fans += kk;
                pred[y].rez += kk + pred[x].rez;
            }
        }
    }
    int getans() {
        vector <pair <pair <int, int>, int>> gl;
        int mx = 0;
        for (int i = 0; i < sz(edge); i++) {
            un(edge[i].X.X, edge[i].X.Y, edge[i].Y);
            mx = max(mx, fans);
        }
        return mx;
    }
};

comp ar[100010];

int a[100010];

int used[100010];

set <pair <int, int>> s;

void dfs(int v) {
    used[v] = 1;
    ar[t].ver.pb({v, a[v]});
    for (auto u : g[v]) {
        if (s.count({min(v, u.X), max(v, u.X)}) == 0) {
            ar[t].edge.pb({{v, u.X}, u.Y});
            s.insert({min(v, u.X), max(v, u.X)});
        }
        if (used[u.X] != 0)
            continue;
        dfs(u.X);
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int x, y, z;
    for (int i = 0; i < m; ++i) {
        cin >> x >> y >> z;
        g[x - 1].pb({y - 1, z});
        g[y - 1].pb({x - 1, z});
    }
    for (int i = 0; i < n; i++) {
        if (used[i] == 0) {
            s.clear();
            dfs(i);
            t++;
        }
    }
    int pans = 0;
    for (int i = 0; i < t; i++) {
        ar[i].build();
        pans = ar[i].getans();
    }
    cout << m - pans << endl;
    return 0;
}


Measured memory_bytes: 50976