#include <iostream>
#include <string>
using namespace std;

class Dice{
public:
	int dice[6];
	int buff1, buff2, buff3;
	void north(){
		buff1 = dice[0];
		buff2 = dice[1];
		buff3 = dice[5];
		dice[5] = dice[4];	// 5 <- 1'
		dice[0] = buff2;	// 0 <- 4
		dice[4] = buff1;	// 4 <- 5'
		dice[1] = buff3;	// 1 <- 0'
	}
	void south(){
		buff1 = dice[0];
		buff2 = dice[1];
		buff3 = dice[5];
		dice[0] = dice[4];	// 0 <- 1'
		dice[1] = buff1;	// 1 <- 5'
		dice[5] = buff2;	// 5 <- 4
		dice[4] = buff3;	// 4 <- 0'
	}
	void west(){
		buff1 = dice[0];
		buff2 = dice[2];
		buff3 = dice[5];
		dice[0] = buff2;	// 0 <- 2'
		dice[2] = buff3;	// 2 <- 5'
		dice[5] = dice[3];	// 5 <- 3
		dice[3] = buff1;	// 3 <- 0'
	}
	void east(){
		buff1 = dice[0];
		buff2 = dice[2];
		buff3 = dice[5];
		dice[2] = buff1;	// 2 <- 0'
		dice[5] = buff2;	// 5 <- 2'
		dice[0] = dice[3];	// 0 <- 3
		dice[3] = buff3;	// 3 <- 5'
	}
};

int main()
{
	Dice d;
	for(int n = 0; n < 6; n++)
		cin >> d.dice[n];

	string command;
	string::iterator itr;
	char direction;
	cin >> command;
	for(itr = command.begin(); itr != command.end(); itr++){
		direction = *itr;
		if(direction == 'N')
			d.north();
		if(direction == 'S')
			d.south();
		if(direction == 'E')
			d.east();
		if(direction == 'W')
			d.west();
	}
	cout << d.dice[0] << endl;
}

#include<bits/stdc++.h>
using namespace std;

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define DISP1(as)		for(auto it : as) cout<<it.f<<" "<<it.s<<") ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	2e+5 + 99;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, k, l, q, x, y;
string s, t;
ll prime[2000000];

// < ----------- func eh ---------------- ? //



// <------------- Start of main() -------------------> //

void MAIN() {
	ll h, m1, m2;
	cin >> h >> m1; m1 += 60 * h;
	cin >> h >> m2; m2 += 60 * h;

	cin>>k;
	m2-=k;

	cout<<max(0ll,m2-m1);newl;
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}