package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}

func Find(R *[][][]int, v int) int {
  nrv := len((*R)[v])
  if v == (*R)[v][nrv - 1][0] { return v }
  return Find(R, (*R)[v][nrv - 1][0])
}
func Union(R, V *[][][]int, u, v, idx int) {
  ru, rv := Find(R, u), Find(R, v)
  nvu, nvv := len((*V)[ru]), len((*V)[rv])
  if ru < rv {
    (*R)[rv] = append((*R)[rv], []int{ru, idx})
    (*V)[ru] = append((*V)[ru], []int{(*V)[ru][nvu - 1][0] + (*V)[rv][nvv - 1][0], idx})
  } else if rv < ru {
    (*R)[ru] = append((*R)[ru], []int{rv, idx})
    (*V)[rv] = append((*V)[rv], []int{(*V)[rv][nvv - 1][0] + (*V)[ru][nvu - 1][0], idx})
  }
}

type Edge [][]int
func (E Edge) Len() int { return len(E) }
func (E Edge) Less(i, j int) bool { return E[i][2] < E[j][2] }
func (E Edge) Swap(i, j int) { E[i], E[j] = E[j], E[i] }

func Solve() {
  var N, M int
  NextInt(&N, &M)
  var X []int
  NextIntVec(&X)
  E := make([][]int, M)
  for i := range E {
    NextIntVec(&E[i])
    E[i][0]--
    E[i][1]--
  }
  sort.Sort(Edge(E))
  R := make([][][]int, N)
  V := make([][][]int, N)
  for i, x := range X {
    R[i] = make([][]int, 0)
    R[i] = append(R[i], []int{i, -1})
    V[i] = make([][]int, 0)
    V[i] = append(V[i], []int{x, -1})
  }
  for i, e := range E {
    u, v := e[0], e[1]
    Union(&R, &V, u, v, i)
  }
  cnt := 0
  for i := M - 1; 0 <= i; i-- {
    e := E[i]
    u, v, x := e[0], e[1], e[2]
    r := Find(&R, u)
    nru, nrv := len(R[u]), len(R[v])
    nvr := len(V[r])
    if x <= V[r][nvr - 1][0] { continue }
    cnt++
    if R[u][nru - 1][1] == i { R[u] = R[u][:nru - 1] }
    if R[v][nrv - 1][1] == i { R[v] = R[v][:nrv - 1] }
    if V[r][nvr - 1][1] == i { V[r] = V[r][:nvr - 1] }
  }
  Write(cnt)
  return
}

func main() {
  Solve()
  Output()
}