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


using ll = long long;
using que_type = tuple<int, pair<int, int>, vector<int>>;

void solve(long long si, long long sj, std::vector<std::vector<long long>> t, std::vector<std::vector<long long>> p){
    priority_queue<que_type, vector<que_type>, greater<que_type>> que;
    que.push(make_tuple(p[si][sj], make_pair(si, sj), vector<int>{(int)t[si][sj]}));

    int times = 1e9;
    int beam = 1000;

    int dx[] = {1, 0, -1, 0};
    int dy[] = {0, 1, 0, -1};
    int ans = 0;
    vector<int> ansv;

    while(times--){
        priority_queue<que_type, vector<que_type>, greater<que_type>> next_que;

        while(!que.empty()){
            que_type q = que.top();
            int score;
            pair<int, int> pos;
            vector<int> tiles;
            tie(score, pos, tiles) = q;

            que.pop();


            for(int i = 0;i < 4;i++){
                int nx = dx[i] + pos.first;
                int ny = dy[i] + pos.second;
                if(0 <= dx[i] + pos.first && dx[i] + pos.first < 50 && 0 <= dy[i] + pos.second && dy[i] + pos.second < 50){
                    bool f = false;
                    for(int x : tiles){
                        if(x == t[nx][ny]){
                            f = true;
                            break;
                        }
                    }
                    if(f == false){
                        tiles.push_back(t[nx][ny]);
                        next_que.push(make_tuple(score + p[nx][ny], make_pair(nx, ny), tiles));
                        tiles.pop_back();
                        if(score + p[nx][ny] > ans){
                            ans = score + p[nx][ny];
                            ansv = tiles;
                        }
                    }
                }
            }
        }
        while(next_que.size() > beam)
            next_que.pop();
        que = next_que;
        //cout<<que.size()<<endl;
        //cout<<ans<<endl;
        if(que.size() == 0){
            break;
        }
    }

    int pi = si;
    int pj = sj;
    string ans_str;
    for(int i = 1;i < ansv.size();i++){
        bool f = false;
        //cout<<ansv[i]<<" ";
        for(int idx = 0;idx < 4;idx++){
            int nx = pi + dx[idx];
            int ny = pj + dy[idx];

            if(0 <= nx && nx < 50 && 0 <= ny && ny < 50){
                if(t[nx][ny] == ansv[i]){
                    //cout<<idx<<" ";
                    if(idx == 0){
                        ans_str.push_back('D');
                    }else
                    if(idx == 1){
                        ans_str.push_back('R');
                    }else
                    if(idx == 2){
                        ans_str.push_back('U');
                    }else
                    if(idx == 3){
                        ans_str.push_back('L');
                    }
                    f = true;
                }
            }
            if(f){
                pi = nx;
                pj = ny;
                break;
            }
        }
    }
    cout<<ans_str<<endl;
}

int main(){
    long long si;
    scanf("%lld",&si);
    long long sj;
    scanf("%lld",&sj);
    std::vector<std::vector<long long>> t(49+1, std::vector<long long>(49+1));
    for(int i = 0 ; i < 49+1 ; i++){
        for(int j = 0 ; j < 49+1 ; j++){
            scanf("%lld",&t[i][j]);
        }
    }
    std::vector<std::vector<long long>> p(49+1, std::vector<long long>(49+1));
    for(int i = 0 ; i < 49+1 ; i++){
        for(int j = 0 ; j < 49+1 ; j++){
            scanf("%lld",&p[i][j]);
        }
    }
    solve(si, sj, std::move(t), std::move(p));
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
//ofstream cout("output.out");

#define fast() {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define pb push_back
#define vi vector<int>
#define vl vector<ll>					
#define vii vector<vector<int>>
#define mii map<int, int>
#define pii pair<int, int>
#define qii priority_que<int, vector<int>, greater<int>>				
#define For(i, n) for(int i = 0; i < n; ++i)
#define For1(i, n) for(int i = 1; i <= n; ++i)
#define Forlr(i, l, r) for(int i = l; i <= r; ++i)
#define Forrl(i, r, l) for(int i = r; i >= l; --i)
#define o(a) { cout << #a << ":" << (a) <<" ";}
#define ov(a) {For(i, a.size()) cout << a[i] <<" ";}
#define ovv(a) {For(i, a.size()) {For(j, a[i].size()) cout << a[i][j] <<" ";cout <<"\n";}}
using ll = long long;
int n, m, k, q;
const int INF = 1e9 + 5;
const int nax = 1e5 + 5;
string s[2005];
ll dp[2005][2005];
const ll mod = 1e9 + 7;
ll x[2000][2000], y[2000][2000], z[2000][2000];

int main()
{
	cin >> n >> m;
	For(i, n){
		cin >> s[i];
	}
	dp[0][0] = 1;
	For(i, n){
		For(j, m){
			//o(s[i][j])
			if(i == 0 && j == 0) continue;
			if(s[i][j] =='#') continue;
			if(i > 0) {
				x[i][j] = (x[i - 1][j] + dp[i - 1][j]) % mod;
			}
			if(j > 0){
				y[i][j] = (y[i][j - 1] + dp[i][j - 1]) % mod;
			}
			if(i > 0 && j > 0){
				z[i][j] = (z[i - 1][j - 1] + dp[i - 1][j - 1]) % mod;
			}
			dp[i][j] = (x[i][j] + y[i][j] + z[i][j]) % mod;
		}
	}
	// For(i, n) {
	// 	For(j, m){
	// 		cout << dp[i][j] << " " ;
	// 	}
	// 	cout <<"\n";
	// }
	cout << dp[n - 1][m - 1];
	//cout << dp[n - 1][m - 1];
}