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

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

alias Edge = Tuple!(int, "u", int, "v", long, "w");

void main() {
    int n, m;
    scan(n, m);
    auto x = readln.split.to!(long[]);
    auto e = new Edge[](m);
    foreach (i ; 0 .. m) {
        int u, v, w;
        scan(u, v, w);
        u--, v--;
        e[i] = Edge(u, v, w);
    }
    e.sort!"a.w < b.w"();

    auto uf = UnionFind(n, x);

    int ans;
    int hen;
    auto mhen = new int[](n);

    foreach (i ; 0 .. m) {
        int u, v; long w;
        u = e[i].u;
        v = e[i].v;
        w = e[i].w;

        if (uf.same(u, v)) {
            auto r = uf.findRoot(u);
            if (w <= uf.wa[r]) {
                hen++;
                mhen[r]++;
            }
            else {
                if (!uf.bad[r]) {
                    uf.bad[r] = true;
                }
            }
            uf.hen[r]++;
        }
        else {
            auto ru = uf.findRoot(u);
            auto henu = uf.hen[ru];
            auto rv = uf.findRoot(v);
            auto henv = uf.hen[rv];

            uf.merge(u, v);
            auto r = uf.findRoot(u);

            if (w > uf.wa[r]) {
                uf.bad[r] = true;
                mhen[r] = mhen[ru] + mhen[rv];
            }
            else {
                hen -= mhen[ru] + mhen[rv];
                hen += uf.hen[r];
                mhen[r] = uf.hen[r];
                uf.bad[r] = false;
            }
        }

        debug {
            writeln(uf.wa);
            writeln(uf.bad);
            writeln(hen);
        }

        ans = max(ans, hen);
    }

    ans = m - ans;

    writeln(ans);
}


struct UnionFind {
    private {
        int _size;
        int[] _parent;
        long[] wa;
        int bcnt;
        bool[] bad;
        int[] hen;
    }

    this(int N, long[] x) 
    in {
        assert(N > 0);
    }
    body {
        _size = N;
        _parent = new int[](_size);
        foreach (i ; 0 .. _size) {
            _parent[i] = i;
        }
        wa = new long[](N);
        wa[] = x.dup;
        bad = new bool[](N);
        hen = new int[](N);
    }

    int findRoot(int x)
    in {
        assert(0 <= x && x < _size);
    }
    body {
        if (_parent[x] != x) {
            _parent[x] = findRoot(_parent[x]);
        }

        return _parent[x];
    }

    bool same(int x, int y)
    in {
        assert(0 <= x && x < _size);
        assert(0 <= y && y < _size);
    }
    body {
        return findRoot(x) == findRoot(y);
    }

    void merge(int x, int y)
    in {
        assert(0 <= x && x < _size);
        assert(0 <= y && y < _size);
    }
    body {
        int u = findRoot(x);
        int v = findRoot(y);

        if (u == v) return;

        _parent[v] = u;
        wa[u] += wa[v];
        wa[v] = 0;

        hen[u] += hen[v] + 1;
        hen[v] = 0;
    }
}






void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}
