#include <bits/stdc++.h>
#define TOP 0
#define FRONT 1
#define LEFT 2
#define RIGHT 3
#define BACK 4
#define BOTTOM 5
using namespace std;

//TOP,FRONT,LEFT,RIGHT,BACK,BOTTOM
int dice[6]={1,2,4,3,5,6};

void rotN(){
  swap(dice[TOP],dice[FRONT]);
  swap(dice[FRONT],dice[BOTTOM]);
  swap(dice[BOTTOM],dice[BACK]);
}

void rotS(){rotN(),rotN(),rotN();}


void rotE(){
  swap(dice[TOP],dice[LEFT]);
  swap(dice[LEFT],dice[BOTTOM]);
  swap(dice[BOTTOM],dice[RIGHT]);
}

void rotW(){rotE(),rotE(),rotE();}


void rotCW(){
  swap(dice[FRONT],dice[RIGHT]);
  swap(dice[RIGHT],dice[BACK]);
  swap(dice[BACK],dice[LEFT]);
}

void rotCCW(){rotCW(),rotCW(),rotCW();}


int main(){
  cin>>dice[TOP]>>dice[FRONT]>>dice[RIGHT];
  cin>>dice[LEFT]>>dice[BACK]>>dice[BOTTOM];
  
  string str;
  cin>>str;
  for(int i=0;i<str.size();i++){
    if(str[i]=='N') rotN();
    if(str[i]=='S') rotS();
    if(str[i]=='E') rotE();
    if(str[i]=='W') rotW();
  }

  cout << dice[TOP]<<endl;
  
}
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
#define mod 1000000007
ll gcd (ll x, ll y){
	ll r = x % y ;
	if(r == 0) return y ;
	return gcd(y, r) ;
}
bool isprime(ll x){
	ll s = sqrt((double) x) ;
	for(ll i = 2; i <= s ; i++){
		if(x % i == 0) return false ; 
	}
	return true ;
}
int main (){
	ll a, b ;
	cin >> a >> b ;
	ll k = gcd(a, b) ;
	ll s = sqrt((double)k) ;
	vector<ll> y ;
	for(ll i = 1; i <= s; i++){
		if(k % i == 0){
			y.push_back(i) ;
			if(i != k/i){
				y.push_back(k/i) ;
			}
		}
	}
	sort(y.begin(), y.end()) ;
	ll num = y.size() ;
	ll ans = 0 ;
	rep(i, num){
		if(isprime(y[i])) ans++ ;
	}
	cout << ans << endl ;
}