type dice = { one : int; two : int; three : int; four : int; five : int; six : int}

type direction = N | S | W | E

let move {one=a;two=b;three=c;four=d;five=e;six=f} = function
    N -> {one=b;two=f;three=c;four=d;five=a;six=e}
  | S -> {one=e;two=a;three=c;four=d;five=f;six=b}
  | W -> {one=c;two=b;three=f;four=a;five=e;six=d}
  | E -> {one=d;two=b;three=a;four=f;five=e;six=c}

let str_to_list str =
  let rec iter l = function
      0 -> l
    | i -> iter (str.[i-1]::l) (i-1)
  in iter [] (String.length str)

let () =
  let dice = Scanf.scanf "%d %d %d %d %d %d\n"
      (fun a b c d e f -> {one=a;two=b;three=c;four=d;five=e;six=f}) in
  let directions = read_line ()
                   |> str_to_list
                   |> List.map
                     (fun d -> match d with 'N'->N | 'S'->S | 'W'->W | _->E) in
  let {one=top;two=_;three=_;four=_;five=_;six=_} =
    List.fold_left (fun dice direction -> move dice direction) dice directions in
  Printf.printf "%d\n" top