#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;

string s[51];
int h,w;

struct Dice{
  int s[6];
  void roll(char c){
    //the view from above
    // N
    //W E
    // S
    //s[0]:top
    //s[1]:south
    //s[2]:east
    //s[3]:west
    //s[4]:north
    //s[5]:bottom
    int b;
    if(c=='E'){
      b=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=b;
    }
    if(c=='W'){
      b=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=b;
    }
    if(c=='N'){
      b=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=b;
    }
    if(c=='S'){
      b=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=b;
    }
    // migi neji (not verified)
    if(c=='R'){
      b=s[1];
      s[1]=s[3];
      s[3]=s[4];
      s[4]=s[2];
      s[2]=b;
    }
    if(c=='L'){
      b=s[1];
      s[1]=s[2];
      s[2]=s[4];
      s[4]=s[3];
      s[3]=b;
    }
  }
  int top() {
    return s[0];
  }
  int hash(){
    int res=0;
    for(int i=0;i<6;i++) res=res*256+s[i];
    return res;
  }
};

struct S{
  int x,y,cost,reach;
  Dice D;
  S(int a,int b,Dice c,int co,int re){
    y=a;
    x=b;
    D=c;
    cost=co;
    reach=re;
  }
};

bool used[31][31][6][6][6];
int A[51][51],y,x;
Dice a;

map<char,int>m;

void init(){
  memset(used,0,sizeof(used));
  m['r']=0;
  m['m']=1;
  m['b']=2;
  m['y']=3;
  m['g']=4;
  m['c']=5;
  m['w']=6;
  m['#']=6;
  m['k']=7;
  a.s[0]=0;
  a.s[1]=1;
  a.s[2]=2;
  a.s[3]=3;
  a.s[4]=4;
  a.s[5]=5;
}

int arr[6],ny,nx;
string t;

int main(){
  while(cin>>w>>h,w){
    init();
    r(i,h)cin>>s[i];
    r(i,h)r(j,w){
      if(s[i][j]=='#')y=i,x=j;
      A[i][j]=m[s[i][j]];
      //cout<<A[i][j]<<endl;
    }
    cin>>t;
    r(i,6)arr[i]=m[t[i]];
    queue<S>q;
    used[y][x][0][1][0]=1;
    q.push(S(y,x,a,0,0));
    while(!q.empty()){
      S p=q.front();q.pop();
      y=p.y;
      x=p.x;
      a=p.D;
      int cost=p.cost;

      if(p.reach==6){
        cout<<cost<<endl;
        goto L;
      }

      ny=y-1;
      nx=x;//cout<<y<<x<<endl;
      if(0<=ny&&ny<h&&0<=nx&&nx<w){//cout<<ny<<nx<<endl;
        if(A[ny][nx]!=7){
          Dice d=a;
          d.roll('N');
          if(A[ny][nx]==6||A[ny][nx]==d.s[0]){
            int re=p.reach;
            if(A[ny][nx]==arr[re])re++;
            if(!used[ny][nx][d.s[0]][d.s[1]][re]){
              if(A[ny][nx]==6||re!=p.reach){
                used[ny][nx][d.s[0]][d.s[1]][re]=1;
                q.push(S(ny,nx,d,cost+1,re));
              }
            }
          }
        }
      }

      ny=y+1;
      nx=x;//cout<<y<<x<<endl;
      if(0<=ny&&ny<h&&0<=nx&&nx<w){//cout<<ny<<nx<<endl;
        if(A[ny][nx]!=7){
          Dice d=a;
          d.roll('S');
          if(A[ny][nx]==6||A[ny][nx]==d.s[0]){
            int re=p.reach;
            if(A[ny][nx]==arr[re])re++;
            if(!used[ny][nx][d.s[0]][d.s[1]][re]){
              if(A[ny][nx]==6||re!=p.reach){
                used[ny][nx][d.s[0]][d.s[1]][re]=1;
                q.push(S(ny,nx,d,cost+1,re));
              }
            }
          }
        }
      }

      ny=y;
      nx=x-1;//cout<<y<<x<<endl;
      if(0<=ny&&ny<h&&0<=nx&&nx<w){//cout<<ny<<nx<<endl;
        if(A[ny][nx]!=7){
          Dice d=a;
          d.roll('W');
          if(A[ny][nx]==6||A[ny][nx]==d.s[0]){
            int re=p.reach;
            if(A[ny][nx]==arr[re])re++;
            if(!used[ny][nx][d.s[0]][d.s[1]][re]){
              if(A[ny][nx]==6||re!=p.reach){
                used[ny][nx][d.s[0]][d.s[1]][re]=1;
                q.push(S(ny,nx,d,cost+1,re));
              }
            }
          }
        }
      }

      ny=y;
      nx=x+1;//cout<<y<<x<<endl;
      if(0<=ny&&ny<h&&0<=nx&&nx<w){//cout<<ny<<nx<<endl;
        if(A[ny][nx]!=7){
          Dice d=a;
          d.roll('E');
          if(A[ny][nx]==6||A[ny][nx]==d.s[0]){
            int re=p.reach;
            if(A[ny][nx]==arr[re])re++;
            if(!used[ny][nx][d.s[0]][d.s[1]][re]){
              if(A[ny][nx]==6||re!=p.reach){
                used[ny][nx][d.s[0]][d.s[1]][re]=1;
                q.push(S(ny,nx,d,cost+1,re));
              }
            }
          }
        }
      }
    }
    cout<<"unreachable"<<endl;
    L:;
  }
}


Measured memory_bytes: 3360