class Dice
    @faces = nil

    def initialize arr
        @faces = arr
    end

    def top
        @faces[0]
    end

    def rotate news
        f = @faces.dup
        case news
        when "N"
            @faces = [f[1], f[5], f[2], f[3], f[0], f[4]]
        when "E"
            @faces = [f[3], f[1], f[0], f[5], f[4], f[2]]
        when "W"
            @faces = [f[2], f[1], f[5], f[0], f[4], f[3]]
        when "S"
            @faces = [f[4], f[0], f[2], f[3], f[5], f[1]]
        end
    end
end

numbers = gets.chomp.split
dice = Dice.new numbers

directions = gets.chomp
directions.each_char{|c| dice.rotate c}

puts dice.top