using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N, M;
        public Graph G;
        public long[] X;

        public void Run()
        {
            // Input
            {
                var line = Input.ReadIntArray();
                N = line[0];
                M = line[1];
            }

            X = Input.ReadLongArray();

            var Edges = new List<Edge>();

            // Graph
            G = new Graph(N);
            for (int i = 0; i < M; i++)
            {
                var line = Input.ReadIntArray();
                int u = line[0] - 1;
                int v = line[1] - 1;
                long y = line[2];
                // 無向グラフ
                var e1 = new Edge(u, v, y);
                var e2 = new Edge(v, u, y);
                e1.Rev = e2;
                e2.Rev = e1;
                G[u].Edges.Add(e1);
                G[v].Edges.Add(e2);

                Edges.Add(e1);
            }

            // 小さい方からソート
            Edges.Sort((e1, e2) => e1.Cost.CompareTo(e2.Cost));

            // UnionFindを作りながら、情報を整理
            var isNG = new bool[M];
            var prev1 = new int[M];
            var prev2 = new int[M];

            var uf = new UnionFind(N, X);

            for (int i = 0; i < M; i++)
            {
                var e = Edges[i];
                var tpl = uf.Unite(e.From, e.To, i);

                // uniteした重みと、以前Uniteした場所
                long weight = tpl.Item1;
                if (weight < e.Cost) isNG[i] = true;
                prev1[i] = tpl.Item2;
                prev2[i] = tpl.Item3;
            }

            // 上から順に見ていく
            int ret = 0;
            bool[] flags = new bool[M];
            flags[M - 1] = true;

            for (int i = M - 1; i >= 0; i--)
            {
                if (flags[i] && isNG[i])
                {
                    ret++;
                    if (prev1[i] != -1) flags[prev1[i]] = true;
                    if (prev2[i] != -1) flags[prev2[i]] = true;
                }
            }

            Console.WriteLine(ret);
        }

    }

    internal class Graph
    {
        public List<Node> Nodes;

        public Node this[int i]
        {
            set { Nodes[i] = value; }
            get { return Nodes[i]; }
        }

        public Graph(int N)
        {
            Nodes = new List<Node>();
            for (int i = 0; i < N; i++)
            {
                Nodes.Add(new Node(i));
            }
        }

    }

    internal class Node
    {
        public List<Edge> Edges;
        public int Dist;
        public int No;

        public Node(int no)
        {
            this.No = no;
            Dist = int.MaxValue;
            Edges = new List<Edge>();
        }
    }

    internal class Edge
    {
        public int From;
        public int To;
        public long Cost;
        public Edge Rev;

        public Edge(int fr, int to, long cost = 0)
        {
            From = fr;
            To = to;
            Cost = cost;
        }

        public bool IsRev(Edge e)
        {
            return Rev != null && (e == Rev);
        }
    }

    // libs ----------
    class UnionFind
    {
        public List<int> Par;
        public List<int> Sizes;
        public List<int> PrevMerged;
        public List<long> Weight;

        public UnionFind(int n, long[] X)
        {
            Par = new List<int>();
            Sizes = new List<int>();
            PrevMerged = new List<int>();
            Weight = new List<long>();

            for (int i = 0; i < n; i++)
            {
                Par.Add(i);
                Sizes.Add(1);
                PrevMerged.Add(-1);
                Weight.Add(X[i]);
            }
        }

        public int Find(int x)
        {
            if (x == Par[x]) return x;
            Par[x] = Find(Par[x]);
            return Par[x];
        }

        public Tuple<long, int, int> Unite(int x, int y, int i)
        {
            x = Find(x);
            y = Find(y);

            if (x == y)
            {
                var tpl0 = Tuple.Create(Weight[x], PrevMerged[x], -1);
                PrevMerged[x] = i;
                return tpl0;
            }

            if (Sizes[x] < Sizes[y])
            {
                // swap
                int temp = x;
                x = y;
                y = temp;
            }

            var tpl = Tuple.Create(Weight[x] + Weight[y], PrevMerged[x], PrevMerged[y]);

            Par[y] = x;
            Sizes[x] += Sizes[y];
            Sizes[y] = 0;

            Weight[x] += Weight[y];
            Weight[y] = 0;
            PrevMerged[x] = i;
            PrevMerged[y] = -1;

            return tpl;
        }

        public bool Same(int x, int y)
        {
            return Find(x) == Find(y);
        }

        public int Size(int x)
        {
            return Sizes[Find(x)];
        }
    }


    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}