#include <cstdio>
#include <cstring>
using namespace std;

int n, k;
int array[10];

int c[4];
bool use[10];
char str[10000][100];
int m;

int number[10000];
int p;

void Search(int i, int j)
{
	if (j == k){
		for (int l = 0; l < k; l++){
			char nstr[3];
			sprintf(nstr, "%d", c[l]);
			strcat(str[m], nstr);
		}
		
		int num;
		sscanf(str[m], "%d", &num);
//		printf("%d\n", num);

		bool f = false;
		for (int l = 0; l < p; l++){
			if (number[l] == num){
				f = true;
				break;
			}
		}
		
		if (!f){
			number[p] = num;
			p++;
		}
		
		m++;
		return;
	}
	
	if (i == n){
		return;
	}
	
	Search(i + 1, j);
	
	if (use[i]){
		return;
	}
	
	c[j] = array[i];
	
	use[i] = true;
	
	Search(0, j + 1);
	
	use[i] = false;
}

int main()
{
	while (scanf("%d %d", &n, &k), n + k){
		memset(array, 0, sizeof(array));
		memset(c, 0, sizeof(c));
		memset(use, 0, sizeof(use));
		memset(str, 0, sizeof(str));
		memset(number, 0, sizeof(number));
		m = 0;
		p = 0;
		
		for (int i = 0; i < n; i++){
			scanf("%d", &array[i]);
		}
		
		Search(0, 0);
		
		printf("%d\n", p);
	}
	
	return 0;
}
#include <iostream>
#include <string>
using namespace std;

class Dice {
  private:
    int *numbers;
  public:
    Dice(int *numbers) {
      this->numbers = numbers;
    }

    int getCurrentNumber() {
      return this->numbers[0];
    }

    void turn(char direction) {
      switch (direction) {
        case 'N':
          this->turnNorth();
          break;
        case 'S':
          this->turnSouth();
          break;
        case 'E':
          this->turnEast();
          break;
        case 'W':
          this->turnWest();
          break;
      }
    }

    void turnNorth() {
      swap(this->numbers[0], this->numbers[1]);
      swap(this->numbers[1], this->numbers[5]);
      swap(this->numbers[5], this->numbers[4]);
    }

    void turnSouth() {
      swap(this->numbers[0], this->numbers[4]);
      swap(this->numbers[4], this->numbers[5]);
      swap(this->numbers[5], this->numbers[1]);
    }

    void turnEast() {
      swap(this->numbers[0], this->numbers[3]);
      swap(this->numbers[3], this->numbers[5]);
      swap(this->numbers[5], this->numbers[2]);
    }

    void turnWest() {
      swap(this->numbers[0], this->numbers[2]);
      swap(this->numbers[2], this->numbers[5]);
      swap(this->numbers[5], this->numbers[3]);
    }
};

int main() {
  int numbers[6];
  char direction;
  string directions;

  for (int i = 0; i < 6; i++) {
    cin >> numbers[i];
  }
  cin >> directions;

  Dice dice(numbers);
  for (int i = 0; i < directions.size(); i++) {
    dice.turn(directions[i]);
  }

  cout << dice.getCurrentNumber() << endl;

  return 0;
}