import scala.io.StdIn.readLine

class Dice(val d:Array[Int]) {

  def roll(dir:Char)  =
    dir match {
      case 'S' => Array(4,0,2,3,5,1)
      case 'N' => Array(1,5,2,3,0,4)
      case 'W' => Array(2,1,5,0,4,3)
      case 'E' => Array(3,1,0,5,4,2)
    }

  def getTopFace(a:Array[Int]):Array[Int] = a.map(d)
}

object Main extends App {
  val faces = readLine.split(" ").map(_.toInt)
  val dice = new Dice(faces)
  val rolls = readLine.foldLeft(Array(0,1,2,3,4,5)) { (x,y) => dice.roll(y).map(x) }

  println(dice.getTopFace(rolls)(0))
}