using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    struct Ind
    {
        public int index1;
        public int index2;
        public Ind(int index1, int index2)
        {
            this.index1 = Min(index1, index2);
            this.index2 = Max(index1, index2);
        }
    }
    class Edge
    { 
        public bool isPass;
        public int weight;
        public Edge(int weight)
        {
            this.weight = weight;
        }

     
    }
    class P
    {
        public int index;
        public List<int> ad;
        public bool isBlack;
        public int parent;
        public int weight;
        public P(int index)
        {
            this.index = index;
            parent = -1;
            weight = int.MaxValue;
            ad = new List<int>();
        }
    }
    static void Main(string[] args)
    {
        var nm = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var p = new P[nm[0]];
        for (var i = 0; i < nm[0]; i++)
            p[i] = new P(i);
        var dic = new Dictionary<Ind, Edge>();
        for (var i = 0; i < nm[1]; i++)
        {
            var input = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
            dic[new Ind(input[0]-1, input[1]-1)] = new Edge(input[2]);
            p[input[0] - 1].ad.Add(input[1]-1);
            p[input[1] - 1].ad.Add(input[0]-1);
        }
        p[0].weight = 0;
        while (true)
        {
            var mincost = int.MaxValue;
            var u = new P(-1);
            for (var i = 0; i < nm[0]; i++)
                if (!p[i].isBlack && p[i].weight < mincost)
                {
                    mincost = p[i].weight;
                    u = p[i];
                }

            if (u.index == -1) break;
            u.isBlack = true;

            foreach(var ad in u.ad)
            {
                var st = new Ind(ad, u.index);
                if(!p[ad].isBlack&&p[ad].weight>dic[st].weight)
                {
                    p[ad].parent = u.index;
                    p[ad].weight = dic[st].weight;
                }
            }
        }
        
        for(var i = 1; i < nm[0]; i++)
        {
            dic[new Ind(i, p[i].parent)].isPass = true;
        }

        WriteLine(dic.Values.Count(e => !e.isPass));
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}
