object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val Array(datN, datM) = readLine.split(" ").map(_.toInt)
    val datH = readLine.split(" ").map(_.toInt)
    val datA = for(i <- 1 to datM) yield (readLine.split(" ").map(_.toInt))

    // make database
    //val rankH = datH.zipWithIndex.map{a => (a._1, a._2 + 1)}.sortBy(_._1).reverse
    val rankH = datH.zipWithIndex.sortWith(_._1 > _._1).map(_._2 + 1)
    //println("DEBUG = " + rankH(0) + " " + rankH(1) + " " + rankH(2) + " " + rankH(3))
    val nodeA = datA.map{x =>
      val a = x(0)
      val b = x(1)
      if(rankH.indexOf(a) < rankH.indexOf(b)) (a, b)
      else if(rankH.indexOf(a) > rankH.indexOf(b)) (b, a)
      else (0, 0)
    }.filter(a => a != (0, 0))
    val mapA = rankH.map{ a =>
      (a, nodeA.filter(b => b._1 == a).map(_._2).toSet)
    }.toMap
    //println("DEBUG = " + mapA)

    // traverse
    def findChildren(result: Set[Int], Hi: Int): Set[Int] = {
      //println("DEBUG2: " + Hi + " " + mapA(Hi))
      if(mapA(Hi).isEmpty) result ++ Set(Hi)
      else mapA(Hi).flatMap(a => findChildren(result, a) ++ Set(Hi))
    }
    def traverseLandscape(result: Int, arrayH: Array[Int]): Int = {
      // mapA: Map[Int, Set[Int]] is used outside
      //println("DEBUG: " + result + " " + arrayH.length)
      if (arrayH.isEmpty) result
      else {
        val Hi = arrayH.head
        val children = findChildren(Set(), Hi).toArray
        traverseLandscape(result + 1, arrayH diff children)
      }
    }

    val ans = traverseLandscape(0, rankH)
    println(ans)
  }
}
