#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

enum Color{
	red,
	cyan,
	green,
	magenta,
	blue,
	yellow,
	white,
	black,
};

char order[25] = "NNNNWNNNWNNNENNNENNNWNNN";

class Cube{
public:
	Cube(){
		init();
	};

	void roll(char dst){
		for(int i = 0; i < 6; i++) work[i] = colors[i];
		switch(dst){
		case 'E':
			setColor(work[3],work[1],work[0],work[5],work[4],work[2]);
			break;
		case 'S':
			setColor(work[1],work[5],work[2],work[3],work[0],work[4]);
			break;
		case 'N':
			setColor(work[4],work[0],work[2],work[3],work[5],work[1]);
			break;
		case 'W':
			setColor(work[2],work[1],work[5],work[0],work[4],work[3]);
			break;
		}
	};

	Color getTop(){
		return colors[0];
	}

	int getPos(){

		Color tmp_colors[6] = {red,green,blue,yellow,magenta,cyan};
		Color tmp_work[6];

		int ret = -1;

		for(int loop = 0; loop < 24; loop++){
			for(int i = 0; i < 6; i++) tmp_work[i] = tmp_colors[i];

			switch(order[loop]){
			case 'E':
				tmp_colors[0] = tmp_work[3];
				tmp_colors[1] = tmp_work[1];
				tmp_colors[2] = tmp_work[0];
				tmp_colors[3] = tmp_work[5];
				tmp_colors[4] = tmp_work[4];
				tmp_colors[5] = tmp_work[2];
				break;
			case 'S':
				tmp_colors[0] = tmp_work[1];
				tmp_colors[1] = tmp_work[5];
				tmp_colors[2] = tmp_work[2];
				tmp_colors[3] = tmp_work[3];
				tmp_colors[4] = tmp_work[0];
				tmp_colors[5] = tmp_work[4];
				break;
			case 'N':
				tmp_colors[0] = tmp_work[4];
				tmp_colors[1] = tmp_work[0];
				tmp_colors[2] = tmp_work[2];
				tmp_colors[3] = tmp_work[3];
				tmp_colors[4] = tmp_work[5];
				tmp_colors[5] = tmp_work[1];
				break;
			case 'W':
				tmp_colors[0] = tmp_work[2];
				tmp_colors[1] = tmp_work[1];
				tmp_colors[2] = tmp_work[5];
				tmp_colors[3] = tmp_work[0];
				tmp_colors[4] = tmp_work[4];
				tmp_colors[5] = tmp_work[3];
				break;
			}

			for(int i = 0; i < 6; i++){
				if(tmp_colors[i] != colors[i])break;
				if(i == 5){
					ret = loop;
					break;
				}
			}
			if(ret != -1)break;
		}
		return ret;
	}

	void setColor(Color n0,Color n1,Color n2,Color n3,Color n4,Color n5){
		colors[0] = n0;
		colors[1] = n1;
		colors[2] = n2;
		colors[3] = n3;
		colors[4] = n4;
		colors[5] = n5;
	}

	void init(){
		setColor(red,green,blue,yellow,magenta,cyan);
	}

	void set(Cube arg){
		for(int i = 0; i < 6; i++){
			colors[i] = arg.colors[i];
		}
	}

	Color colors[6];
	Color work[6];
};

struct Info{
	int row,col;
};

struct Data{
	void set(int arg_row,int arg_col,int arg_state,Color arg_last_visited,int arg_cost){
		loc.row = arg_row;
		loc.col = arg_col;
		state = arg_state;
		last_visited = arg_last_visited;
		cost = arg_cost;
	}
	Cube cube;
	Info loc;
	int state,cost;
	Color last_visited;
};

int H,W,diff_row[4] = {-1,0,0,1},diff_col[4] = {0,-1,1,0},POW[6];
char map[30][31],dir[4] = {'N','W','E','S'};
int dp[30][30][64][24]; //dp[row][col][state][cube-pos]
Color visit_order[6];
Info info[6];

bool rangeCheck(int row,int col){
	if(row >= 0 && row <= H-1 && col >= 0 && col <= W-1)return true;
	else{
		return false;
	}
}

void func(){

	for(int a = 0; a < H; a++){
		for(int b = 0;b < W;b++){
			for(int c = 0; c < 64; c++){
				for(int d = 0; d < 24; d++)dp[a][b][c][d] = BIG_NUM;
			}
		}
	}

	int start_row,start_col;

	for(int i = 0; i < H; i++){
		scanf("%s",map[i]);
		for(int k = 0; k < W; k++){
			switch(map[i][k]){
			case '#':
				start_row = i;
				start_col = k;
				map[i][k] = 'w';
				break;
			case 'r':
				info[red].row = i;
				info[red].col = k;
				break;
			case 'g':
				info[green].row = i;
				info[green].col = k;
				break;
			case 'b':
				info[blue].row = i;
				info[blue].col = k;
				break;
			case 'c':
				info[cyan].row = i;
				info[cyan].col = k;
				break;
			case 'm':
				info[magenta].row = i;
				info[magenta].col = k;
				break;
			case 'y':
				info[yellow].row = i;
				info[yellow].col = k;
				break;
			}
		}
	}

	char buf[7];
	scanf("%s",buf);

	for(int i = 0; i < 6; i++){

		switch(buf[i]){
		case 'r':
			visit_order[i] = red;
			break;
		case 'g':
			visit_order[i] = green;
			break;
		case 'b':
			visit_order[i] = blue;
			break;
		case 'c':
			visit_order[i] = cyan;
			break;
		case 'm':
			visit_order[i] = magenta;
			break;
		case 'y':
			visit_order[i] = yellow;
			break;
		}
	}

	Color last_color = visit_order[5];

	Color pre_color[6];
	pre_color[visit_order[0]] = white;

	for(int i = 1; i <= 5; i++){
		pre_color[visit_order[i]] = visit_order[i-1];
	}

	Data first;
	first.set(start_row,start_col,0,white,0);

	dp[start_row][start_col][0][first.cube.getPos()] = 0;

	queue<Data> Q;
	Q.push(first);

	int next_row,next_col,next_state,tmp;

	while(!Q.empty()){

		if(Q.front().loc.row == info[last_color].row && Q.front().loc.col == info[last_color].col){
			printf("%d\n",Q.front().cost);
			return;
		}else if(Q.front().cost > dp[Q.front().loc.row][Q.front().loc.col][Q.front().state][Q.front().cube.getPos()]){
			Q.pop();
		}else{

			for(int i = 0; i < 4; i++){
				next_row = Q.front().loc.row + diff_row[i];
				next_col = Q.front().loc.col + diff_col[i];

				if(rangeCheck(next_row,next_col) == false || map[next_row][next_col] == 'k')continue;

				Data next_data;
				next_data.cube.set(Q.front().cube);

				next_data.cube.roll(dir[i]);

				tmp = next_data.cube.getPos();

				switch(map[next_row][next_col]){
				case 'w':
					if(dp[next_row][next_col][Q.front().state][tmp] > Q.front().cost+1){
						dp[next_row][next_col][Q.front().state][tmp] = Q.front().cost+1;
						next_data.set(next_row,next_col,Q.front().state,Q.front().last_visited,Q.front().cost+1);
						Q.push(next_data);
					}
					break;
				case 'r':
					if(Q.front().last_visited == pre_color[red] && next_data.cube.getTop() == red){
						next_state = Q.front().state + POW[red];

						if(dp[next_row][next_col][next_state][tmp] > Q.front().cost+1){
							dp[next_row][next_col][next_state][tmp] = Q.front().cost+1;
							next_data.set(next_row,next_col,next_state,red,Q.front().cost+1);
							Q.push(next_data);
						}
					}
					break;
				case 'g':
					if(Q.front().last_visited == pre_color[green] && next_data.cube.getTop() == green){
						next_state = Q.front().state + POW[green];

						if(dp[next_row][next_col][next_state][tmp] > Q.front().cost+1){
							dp[next_row][next_col][next_state][tmp] = Q.front().cost+1;
							next_data.set(next_row,next_col,next_state,green,Q.front().cost+1);
							Q.push(next_data);
						}
					}
					break;
				case 'b':
					if(Q.front().last_visited == pre_color[blue] && next_data.cube.getTop() == blue){
						next_state = Q.front().state + POW[blue];

						if(dp[next_row][next_col][next_state][tmp] > Q.front().cost+1){
							dp[next_row][next_col][next_state][tmp] = Q.front().cost+1;
							next_data.set(next_row,next_col,next_state,blue,Q.front().cost+1);
							Q.push(next_data);
						}
					}
					break;
				case 'c':
					if(Q.front().last_visited == pre_color[cyan] && next_data.cube.getTop() == cyan){
						next_state = Q.front().state + POW[cyan];

						if(dp[next_row][next_col][next_state][tmp] > Q.front().cost+1){
							dp[next_row][next_col][next_state][tmp] = Q.front().cost+1;
							next_data.set(next_row,next_col,next_state,cyan,Q.front().cost+1);
							Q.push(next_data);
						}
					}
					break;
				case 'm':
					if(Q.front().last_visited == pre_color[magenta] && next_data.cube.getTop() == magenta){
						next_state = Q.front().state + POW[magenta];

						if(dp[next_row][next_col][next_state][tmp] > Q.front().cost+1){
							dp[next_row][next_col][next_state][tmp] = Q.front().cost+1;
							next_data.set(next_row,next_col,next_state,magenta,Q.front().cost+1);
							Q.push(next_data);
						}
					}
					break;
				case 'y':
					if(Q.front().last_visited == pre_color[yellow] && next_data.cube.getTop() == yellow){
						next_state = Q.front().state + POW[yellow];

						if(dp[next_row][next_col][next_state][tmp] > Q.front().cost+1){
							dp[next_row][next_col][next_state][tmp] = Q.front().cost+1;
							next_data.set(next_row,next_col,next_state,yellow,Q.front().cost+1);
							Q.push(next_data);
						}
					}
					break;
				}
			}
			Q.pop();
		}
	}

	printf("unreachable\n");
}

int main(){

	for(int i = 0; i <= 5; i++)POW[i] = pow(2,i);

	while(true){
		scanf("%d %d",&W,&H);
		if(W == 0 && H == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 8724