import scala.io.StdIn._
import scala.annotation.tailrec

object Main {

  object Dice{
    private val north = List(2,6,3,4,1,5).map(_-1)
    private val east = List(4,2,1,6,5,3).map(_-1)
    private val ccw = List(3,2,6,1,5,4).map(_-1)
  }

  case class Dice(pip: List[Int]) {
    private def north = Dice(Dice.north.map(pip))
    private def east = Dice(Dice.east.map(pip))
    private def south = north.north.north
    private def west = east.east.east

    def rotate(com: Char):Dice = com match {
      case 'N' => north
      case 'E' => east
      case 'S' => south
      case 'W' => west
      case _ => this
    }
  }

  @tailrec
  def loop(com: String, dice: Dice):Dice = {
    if(com.isEmpty)dice
    else loop(com.tail,dice.rotate(com.head))
  }

  def main(args: Array[String]): Unit = {
    val pip = readLine.split(" ").map(_.toInt).toList
    println(loop(readLine,Dice(pip)).pip(0))
  }
}