import scala.collection.mutable
object Main extends App {
  import scala.io.StdIn._

  val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
  val vertexs = readLine.trim.split(' ').map(_.toLong)
  val union = vertexs.map(w ⇒ new UnionFindTree(w))
  val nodes = Array.tabulate(n){_ ⇒ Nil: List[(Int, Long)]}
  val edges = Array.tabulate(m){_ ⇒
    val Array(a, b, y) = readLine.trim.split(' ').map(_.toInt)
    nodes(a - 1) ::= (b - 1, y)
    nodes(b - 1) ::= (a - 1, y)
    Edge(a - 1, b - 1, y)
  }.sortBy(_.weight)
  val needNotRemove = Array.tabulate(m){_ ⇒ false}
  for (i ← edges.indices){
    union(edges(i).from).merge(union(edges(i).to))
    if (union(edges(i).from).weight >= edges(i).weight) {
      needNotRemove(i) = true
    }
  }
  val max = Array.tabulate(n){_ ⇒ 0L}
  val queue = mutable.Queue[Int]()
  for (i ← needNotRemove.indices if needNotRemove(i)){
    val weight = edges(i).weight
    if (max(edges(i).from) < weight) {
      queue.enqueue(edges(i).from)
      max(edges(i).from) = weight
      while (queue.nonEmpty) {
        val top = queue.dequeue()
        for ((to, w) ← nodes(top) if w <= weight && max(to) < weight) {
          max(to) = weight
          queue.enqueue(to)
        }
      }
    }
  }

  println(edges.count(e ⇒ max(e.from) < e.weight || max(e.to) < e.weight))

  case class Edge(from: Int, to: Int, weight: Long)
  class UnionFindTree(private var mWeight: Long){
    private var mParent: Option[UnionFindTree] = None
    private var mSize: Int = 1
    private def parent: UnionFindTree = {
      mParent.map{_.parent} match {
        case None ⇒ this
        case c@Some(p) ⇒
          mParent = c
          p
      }
    }
    def weight: Long = parent.mWeight
    def size: Int = parent.mSize
    def isTop: Boolean = mParent.isEmpty
    def isSameUnion(that: UnionFindTree): Boolean = {
      parent == that.parent
    }
    def merge(that: UnionFindTree): Unit = {
      if (!isSameUnion(that)){
        val p = parent
        val tp = that.parent
        if (p.mSize > tp.mSize){
          tp.mParent = Some(p)
          p.mSize += tp.mSize
          p.mWeight += tp.mWeight
        }else {
          p.mParent = Some(tp)
          tp.mSize += p.mSize
          tp.mWeight += p.mWeight
        }
      }
    }
  }
}