#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#define inf 1000000000

using namespace std;

struct State{
	int top, north, west;
	State(){}
	State(int a, int b, int c){
		top = a, north = b, west = c;
	}
	bool operator<(State ope){
		if(top < ope.top) return true;
		if(top == ope.top && north < ope.north) return true;
		if(top == ope.top && north == ope.north && west < ope.west) return true;
		return false;
	}
	void moveLeft(){
		int tmp = west;
		west = top;
		top = 7 - tmp;
	}
	void moveRight(){
		int tmp = top;
		top = west;
		west = 7 - tmp;
	}
	void moveUp(){
		int tmp = north;
		north = top;
		top = 7 - tmp;
	}
	void moveDown(){
		int tmp = top;
		top = north;
		north = 7 - tmp;
	}
	void rotate(){
		int tmp = west;
		west = north;
		north = 7 - tmp;
	}
};

int w, d;
char map[35][35];
int sx[7], sy[7];
char v[7];

int dp[7][24];
int dist[24][35][35];

vector<State> vec_state;
int trans[24][4];

void makeStateTable()
{
	State state = State(1, 2, 3);
	for(int i = 0; i < 4; i++){
		state.rotate();
		vec_state.push_back(state);
	}
	state.moveDown();
	for(int i = 0; i < 4; i++){
		state.rotate();
		vec_state.push_back(state);
	}
	state.moveRight();
	for(int i = 0; i < 4; i++){
		state.rotate();
		vec_state.push_back(state);
	}
	state.moveRight();
	for(int i = 0; i < 4; i++){
		state.rotate();
		vec_state.push_back(state);
	}
	state.moveRight();
	for(int i = 0; i < 4; i++){
		state.rotate();
		vec_state.push_back(state);
	}
	state.moveDown();
	for(int i = 0; i < 4; i++){
		state.rotate();
		vec_state.push_back(state);
	}
	sort(vec_state.begin(), vec_state.end());
}

void makeTrans()
{
	State tmp;
	for(int i = 0; i < 24; i++){
		tmp = vec_state[i], tmp.moveRight();
		trans[i][0] = lower_bound(vec_state.begin(), vec_state.end(), tmp) - vec_state.begin();
		tmp = vec_state[i], tmp.moveUp();
		trans[i][1] = lower_bound(vec_state.begin(), vec_state.end(), tmp) - vec_state.begin();
		tmp = vec_state[i], tmp.moveLeft();
		trans[i][2] = lower_bound(vec_state.begin(), vec_state.end(), tmp) - vec_state.begin();
		tmp = vec_state[i], tmp.moveDown();
		trans[i][3] = lower_bound(vec_state.begin(), vec_state.end(), tmp) - vec_state.begin();
	}
}

struct pos{
	int x, y, state;
	pos(){}
	pos(int a, int b, int c){
		x = a, y = b, state = c;
	}
};

void bfs(int sx, int sy, int state)
{
	const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};

	for(int s = 0; s < 24; s++){
		for(int x = 0; x < w; x++){
			for(int y = 0; y < d; y++){
				dist[s][x][y] = inf;
			}
		}
	}
	queue<pos> Q;
	Q.push(pos(sx, sy, state));
	dist[state][sx][sy] = 0;
	
	pos p;
	int x, y, st;
	int nx, ny, nst;
	
	while(Q.size()){
		p = Q.front(); Q.pop();
		x = p.x, y = p.y, st = p.state;
		if(map[x][y] != 'w' && map[x][y] != 'k') continue;
		for(int dir = 0; dir < 4; dir++){
			nx = x + dx[dir], ny = y + dy[dir], nst = trans[st][dir];
			if(nx < 0 || nx >= w || ny < 0 || ny >= d) continue;
			if(map[nx][ny] == 'k') continue; 
			if(dist[nst][nx][ny] < inf) continue;
			if(map[nx][ny] != 'w'){
				if(vec_state[nst].top != map[nx][ny] - '0') continue;
			}
			
			dist[nst][nx][ny] = dist[st][x][y] + 1;
			Q.push(pos(nx, ny, nst));
		}
	}
}

void input()
{
	for(int y = 0; y < d; y++){
		for(int x = 0; x < w; x++){
			cin >> map[x][y];
			if(map[x][y] == '#'){
				sx[0] = x, sy[0] = y;
				map[x][y] = 'w';
			}
		}
	}
	for(int i = 1; i <= 6; i++) cin >> v[i];
	
	for(int i = 1; i <= 6; i++){
		for(int y = 0; y < d; y++){
			for(int x = 0; x < w; x++){
				if(map[x][y] == v[i]){
					sx[i] = x, sy[i] = y;
					if(map[x][y] == 'r') map[x][y] = '1';
					if(map[x][y] == 'c') map[x][y] = '6';
					if(map[x][y] == 'g') map[x][y] = '2';
					if(map[x][y] == 'm') map[x][y] = '5';
					if(map[x][y] == 'b') map[x][y] = '4';
					if(map[x][y] == 'y') map[x][y] = '3';
					goto end;
				}
			}
		}
		end:;
	}
}

int main(void)
{
	makeStateTable();
	makeTrans();
	
	while(1){
		cin >> w >> d;
		if(w == 0 && d == 0) break;
		
		input();
	
		for(int i = 0; i <= 6; i++){
			for(int j = 0; j < 24; j++){
				dp[i][j] = inf;
			}
		}
		dp[0][0] = 0;
		
		for(int i = 0; i < 6; i++){
			for(int j = 0; j < 24; j++){
				if(dp[i][j] >= inf) continue;
				bfs(sx[i], sy[i], j);
				
				for(int nj = 0; nj < 24; nj++){
					dp[i+1][nj] = min(dp[i+1][nj], dp[i][j] + dist[nj][sx[i+1]][sy[i+1]]);
				}
			}
			map[sx[i+1]][sy[i+1]] = 'k';
		}
		
		int ans = inf;
		for(int i = 0; i < 24; i++){
			ans = min(ans, dp[6][i]);
		}
		if(ans >= inf) cout << "unreachable" << endl;
		else cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3124