#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

enum {
  RED = 0,
  MAGENTA,
  BLUE,
  YELLOW,
  GREEN,
  CYAN
};

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

struct Dice {
  int cost;
  int top;
  int front;
  int right;
  int order;
  int x;
  int y;
  Dice() {;}
  Dice(int c, int t, int f, int r, int order, int x, int y) : cost(c), top(t), front(f), right(r), order(order), x(x), y(y) {;}
  void Rotate(int i) {
    int ntop = top;
    int nfront = front;
    int nright = right;
    if (i == 0) {
      ntop = 5 - right;
      nright = top;
    } else if (i == 1) {
      ntop = 5 - front;
      nfront = top;
    } else if (i == 2) {
      ntop = right;
      nright = 5 - top;
    } else if (i == 3) {
      ntop = front;
      nfront = 5 - top;
    }
    top = ntop;
    front = nfront;
    right = nright;
    x += dx[i];
    y += dy[i];
    cost++;
  }
};

int mapto[200];
int order[200];
int w, h;
char field[40][40];
bool visit[7][6][6][30][30];
char str[100];

int main() {
  mapto['r'] = RED;
  mapto['g'] = GREEN;
  mapto['b'] = BLUE;
  mapto['c'] = CYAN;
  mapto['m'] = MAGENTA;
  mapto['y'] = YELLOW;
  MEMSET(order, -1);
  while (scanf("%d %d", &w, &h), w|h) {
    MEMSET(visit, false);
    int sx, sy;
    REP(y, h) { scanf("%s", field[y]); }
    scanf("%s", str);
    REP(i, 6) {
      order[(int)str[i]] = i;
    }
    REP(y, h) REP(x, w) {
      if (field[y][x] == '#') {
        sx = x;
        sy = y;
        field[y][x] = 'w';
        break;
      }
    }
    queue<Dice> que;
    que.push(Dice(0, 0, 1, 2, 0, sx, sy));
    while (!que.empty()) {
      Dice dice = que.front();
      que.pop();
      //cout << dice.x << " " << dice.y << " " << dice.order << endl;
      if (dice.order == 6) {
        printf("%d\n", dice.cost);
        goto next;
      }
      REP(i, 4) {
        Dice ndice = dice;
        ndice.Rotate(i);
        if (ndice.x < 0 || ndice.x >= w || ndice.y < 0 || ndice.y >= h) { continue; }
        char f = field[ndice.y][ndice.x];
        if (f == 'k') { continue; }
        if (f != 'w' && ndice.order != order[(int)f]) { continue; }
        if (f != 'w') {
          if (mapto[(int)f] != ndice.top) { continue; }
          ndice.order++;
        }
        if (visit[ndice.order][ndice.top][ndice.front][ndice.y][ndice.x]) { continue; }
        visit[ndice.order][ndice.top][ndice.front][ndice.y][ndice.x] = true;
        que.push(ndice);
      }
    }
    puts("unreachable");
next:;
  }
}