package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
type edge struct {
	from, to, cost int
}
type ES []edge

func (e ES) Len() int {
	return len(e)
}
func (e ES) Less(i, j int) bool {
	return e[i].cost < e[j].cost
}
func (e ES) Swap(i, j int) {
	e[i], e[j] = e[j], e[i]
}

func main() {
	defer stdout.Flush()

	n := readInt()
	m := readInt()

	es := make([]edge, m)
	for i := 0; i < m; i++ {
		a := readInt()
		b := readInt()
		c := readInt()
		es[i].from = a
		es[i].to = b
		es[i].cost = c
	}
	sort.Sort(ES(es))

	uf := NewUnionFind(n + 1)
	var ans int
	for _, e := range es {
		if uf.Find(e.from) == uf.Find(e.to) {
			ans++
			continue
		}
		uf.Union(e.from, e.to)
	}
	println(ans)
}

type UnionFind struct {
	parent []int
	rank   []int
}

func NewUnionFind(n int) *UnionFind {
	u := &UnionFind{
		parent: make([]int, n),
		rank:   make([]int, n),
	}

	for i := range u.parent {
		u.parent[i] = i
		u.rank[i] = 0
	}

	return u
}

func (u *UnionFind) Find(i int) int {
	if u.parent[i] == i {
		return i
	}
	p := u.Find(u.parent[i])
	u.parent[i] = p
	return p
}

func (u *UnionFind) Union(i, j int) {
	pi := u.Find(i)
	pj := u.Find(j)

	if pi == pj {
		return
	}

	if u.rank[pi] > u.rank[pj] {
		u.parent[pj] = pi
	} else {
		u.parent[pi] = pj
		if u.rank[pi] == u.rank[pj] {
			u.rank[pj]++
		}
	}
}
