#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    while(1){
        int h,w;
        cin >> h >> w;
        if(h == 0) break;

        vector<int> posy(256), posx(256);
        for(int i=0; i<h; i++){
            string s;
            cin >> s;
            for(int j=0; j<w; j++){
                posy[s[j]] = i;
                posx[s[j]] = j;
            }
        }
        string s;
        cin >> s;
        int y=0, x=0;
        int ans = 0;
        for(char c: s){
            int p = c;
            ans += abs(posy[p]-y);
            ans += abs(posx[p]-x);
            ans++;
            y = posy[p];
            x = posx[p];
        }
        cout << ans << endl;
    }
    return 0;
}
