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


  val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
  val direction = readLine.trim.map(_ == 'R').toArray
  val costs = readLine.trim.split(' ').map(_.toInt)
  val relation = Array.tabulate(m){_ ⇒
    val Array(s, t, b) = readLine.trim.split(' ').map(_.toInt)
    if (s < t) (s, t, b) else (t, s, b)
  }
  println(
    calMinCut(direction, costs, relation)
  )

  def calMinCut(direction: Array[Boolean], costs: Array[Int], relations: Array[(Int, Int, Int)]): Long = {
    val source = 0
    val drain = direction.length + 1
    val nodes = Array.tabulate(direction.length + 2){_ ⇒ ArrayBuffer[Edge]()}
    for (i ← direction.indices){
      if (direction(i)){
        nodes(i + 1).append(Edge(drain, nodes(drain).length, costs(i)))
        nodes(drain).append(Edge(i + 1, 0, 0))
      }else {
        nodes(i + 1).append(Edge(source, nodes(source).length, 0))
        nodes(source).append(Edge(i + 1, 0, costs(i)))
      }
    }
    for ((s, t, b) ← relations){
      nodes(t).append(Edge(s, nodes(s).length, b))
      nodes(s).append(Edge(t, nodes(t).length - 1, 0))
    }
    calMinCut(nodes, source, drain)
  }
  def calMinCut(nodes: Array[ArrayBuffer[Edge]], source: Int, drain: Int): Long = {
    val depth = Array.tabulate(nodes.length){_ ⇒ 0}
    val searching = Array.tabulate(nodes.length){_ ⇒ 0}
    val queue = mutable.Queue[Int]()
    def bfs(): Unit ={
      queue.clear()
      queue.enqueue(source)
      depth.indices.foreach(i ⇒ depth(i) = -1)
      depth(source) = 0
      while (queue.nonEmpty && queue.head != drain){
        val current = queue.dequeue()
        for (next ← nodes(current) if next.flow > 0 && depth(next.to) == -1){
          depth(next.to) = depth(current) + 1
          queue.enqueue(next.to)
        }
      }
    }
    def dfs(current: Int, minFlow: Long = Long.MaxValue): Long = {
      if (current == drain) minFlow
      else {
        var flow = 0L
        while(searching(current) < nodes(current).length && flow == 0) {
          val next = nodes(current)(searching(current))
          if (next.flow > 0 && depth(current) < depth(next.to)) {
            flow = dfs(next.to, math.min(minFlow, next.flow))
            if (flow != 0) {
              next.flow -= flow
              nodes(next.to)(next.pair).flow += flow
              searching(current) -= 1
            }
          }
          searching(current) += 1
        }
        flow
      }
    }
    var result = 0L
    var canFlow = true
    while(canFlow){
      bfs()
      searching.indices.foreach(i ⇒ searching(i) = 0)
      canFlow = false
      var r = dfs(source)
      while(r != 0){
        canFlow = true
        result += r
        r = dfs(source)
      }
    }
    result
  }
  case class Edge(to: Int, pair: Int, var flow: Long)

  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def let[A](func: T ⇒ A): A = func(value)
  }
}

