import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto X = readln.split.map!(to!long).array;
    auto G = new Tuple!(int, long)[][](N);
    auto E = new Tuple!(int, int, long)[](M);
    foreach (i; 0..M) {
        s = readln.split.map!(to!int);
        G[s[0]-1] ~= tuple(s[1]-1, s[2].to!long);
        G[s[1]-1] ~= tuple(s[0]-1, s[2].to!long);
        E[i] = tuple(s[0]-1, s[1]-1, s[2].to!long);
    }

    E.sort!"a[2] < b[2]";
    auto uf = new UnionFind(N, X);

    foreach (e; E) {
        uf.unite(e[0], e[1]);
        int u = uf.find(e[0]);
        if (uf.weights[u] >= e[2]) {
            uf.unused_edges[u] = 0;
        }
    }

    int u = uf.find(0);
    uf.unused_edges[u].writeln;
}



class UnionFind {
    int N;
    int[] table;
    long[] weights;
    long[] unused_edges;

    this(int n, long[] X) {
        N = n;
        table = new int[](N);
        fill(table, -1);
        weights = new long[](N);
        foreach (i; 0..N) weights[i] = X[i];
        unused_edges = new long[](N);
    }

    int find(int x) {
        return table[x] < 0 ? x : (table[x] = find(table[x]));
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (table[x] > table[y]) swap(x, y);
        unused_edges[x] += 1;
        if (x == y) return;
        weights[x] += weights[y];
        unused_edges[x] += unused_edges[y];
        table[x] += table[y];
        table[y] = x;
    }
}
