#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(x) x.begin(), x.end()
#define SZ(x) ((int)x.size())

using pii = pair<int, int>;
using pcc = pair<char, char>;
int dy[4] = {-1, 0, 1, 0};
int dx[4] = {0, 1, 0, -1};

template <class T>
struct Dice {
    enum FACE {
        NORTH,
        WEST,
        TOP,
        EAST,
        BOTTOM,
        SOUTH
    };
    
    T face[6];
    
    Dice(T top, T bottom, T north, T south, T west, T east) {
        face[TOP] = top;
        face[BOTTOM] = bottom;
        face[NORTH] = north;
        face[SOUTH] = south;
        face[WEST] = west;
        face[EAST] = east;
    }
    Dice() {}
    
    void rotate(int dir) {
        switch (dir) {
        case 0:
            {T tmp = face[2]; face[2] = face[5]; face[5] = face[4]; face[4] = face[0]; face[0] = tmp;}
            break;
        case 1:
            {T tmp = face[2]; face[2] = face[1]; face[1] = face[4]; face[4] = face[3]; face[3] = tmp;}
            break;
        case 2:
            {T tmp = face[2]; face[2] = face[0]; face[0] = face[4]; face[4] = face[5]; face[5] = tmp;}
            break;
        case 3:
            {T tmp = face[2]; face[2] = face[3]; face[3] = face[4]; face[4] = face[1]; face[1] = tmp;}
            break;
        case 4: // unimplemented
        case 5:
            assert(false);
            break;
        }
    }

    T get(FACE f) {
        return face[f];
    }
    
    bool operator<(const Dice &r) const {
        return face[TOP] == r.face[TOP] ? (face[SOUTH] < r.face[SOUTH]) : (face[TOP] < r.face[TOP]);
    }
};

signed main() {
    while (1) {
        int w, h;
        cin >> w >> h;
        if (w == 0 && h == 0) break;
        vector<string> s(h);
        int py, px;
        REP(i, h) {
            cin >> s[i];
            REP(j, w) if (s[i][j] == '#') py = i, px = j, s[i][j] = 'w';
        }
        string v;
        cin >> v;

        using state = tuple<Dice<char>, pii, int>;
        map<state, int> dist;
        queue<state> q;
        auto ini = make_tuple(Dice<char>('r', 'c', 'g', 'm', 'y', 'b'), make_pair(py, px), 0);
        q.push(ini);
        dist[ini] = 0;

        int ans = -1;
        while (!q.empty()) {
            auto cur = q.front(); q.pop();
            Dice<char> dice;
            pii pos;
            int seq;
            tie(dice, pos, seq) = cur;

            if (seq == 6) {
                ans = dist[cur];
                break;
            }

            REP(dir, 4) {
                int ny = pos.first + dy[dir];
                int nx = pos.second + dx[dir];
                if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
                if (s[ny][nx] == 'k') continue;
                
                auto ndice = dice;
                ndice.rotate(dir);
                if (s[ny][nx] != 'w' && (ndice.get(Dice<char>::TOP) != s[ny][nx] || s[ny][nx] != v[seq])) continue;

                int nseq = seq;
                if (s[ny][nx] == v[seq]) nseq++;
                auto nstate = make_tuple(ndice, pii(ny, nx), nseq);
                if (dist.find(nstate) == dist.end()) {
                    dist[nstate] = dist[cur] + 1;
                    q.push(nstate);
                }
            }
        }

        if (ans == -1) cout << "unreachable" << endl;
        else cout << ans << endl;
    }
}



Measured memory_bytes: 8404