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

#define INF 0x3fffffff

typedef pair<int, int> Pos;
typedef pair<int, Pos> Data;
typedef pair<string, Data> Pair;
enum Dir {TOP, BOTTOM, NORTH, SOUTH, EAST, WEST};

string first_die = "rcgmby";
int dx[] = {0, -1, 0, 1};
int dy[] = {-1, 0, 1, 0};

int w;
int d;
char field[30][30];
char vs[8];
map<string, int> mind[8][30][30];
map<char, Pos> pos;

string Rotate(string die, vector<int> dirs) {
  string newdie = die;
  for (int i=0; i<4; i++) {
    newdie[dirs[(i+1)%4]] = die[dirs[i]];
  }
  return newdie;
}

string Advance(string die) {
  return Rotate(die, vector<int>{TOP, NORTH, BOTTOM, SOUTH});
}

string RotateRight(string die) {
  return Rotate(die, vector<int>{NORTH, EAST, SOUTH, WEST});
}

string RotateLeft(string die) {
  return Rotate(die, vector<int>{NORTH, WEST, SOUTH, EAST});
}

bool WithinRange(int y, int x) {
  if (y < 0 || d <= y) return false;
  if (x < 0 || w <= x) return false;
  return true;
}

int main() {
  while (1) {
    scanf("%d%d", &w, &d);
    if ((w|d) == 0) return 0;

    for (int i=0; i<d; i++) {
      for (int j=0; j<w; j++) {
        scanf(" %c", &field[i][j]);
        pos[field[i][j]] = Pos(i, j);
        for (int k=0; k<7; k++) mind[k][i][j].clear();
      }
    }

    vs[0] = '#';
    scanf("%s", &vs[1]);

    mind[0][pos[vs[0]].first][pos[vs[0]].second][first_die] = 0;
    queue<Pair> q;
    q.push(Pair(first_die, Data(0, pos[vs[0]])));
    while (!q.empty()) {
      int y, x;
      Pair p = q.front(); q.pop();
      string die = p.first;
      Data d = p.second;
      int t = d.first;
      tie(y, x) = d.second;
      //cout << t << " " << y << " " << x << "\n";
      //cout << "TOP: " << die[TOP] << "\n";
      //cout << "BOTTOM: " << die[BOTTOM] << "\n";
      int cost = mind[t][y][x][die];
      for (int i=0; i<4; i++) {
        int newx = x+dx[i];
        int newy = y+dy[i];
        if (!WithinRange(newy, newx)) continue;
        if (field[newy][newx] == 'k') continue;

        bool found = false;
        for (int j=1; j<7; j++) {
          if (j == t+1) continue;
          if (pos[vs[j]] == Pos(newy, newx)) {
            found = true;
            break;
          }
        }
        if (found) continue;

        int newt = t;
        if (field[newy][newx] == vs[t+1]) newt++;

        string newdie = die;
        for (int j=0; j<i; j++) {
          newdie = RotateRight(newdie);
        }
        newdie = Advance(newdie);
        for (int j=0; j<i; j++) {
          newdie = RotateLeft(newdie);
        }
        if (mind[newt][newy][newx].count(newdie)) continue;

        if (field[newy][newx] == vs[t+1]) {
          if (newdie[TOP] != vs[t+1]) continue;
        }

        mind[newt][newy][newx][newdie] = cost+1;
        q.push(Pair(newdie, Data(newt, Pos(newy, newx))));
      }
    }

    int ans = INF;
    for (auto itr : mind[6][pos[vs[6]].first][pos[vs[6]].second]) {
      ans = min(ans, itr.second);
    }
    if (ans == INF) puts("unreachable");
    else printf("%d\n", ans);
  }
}