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

int func(int a, int b, int c, int d) {
	if (a >= b) {
		if (a >= c) {
			if (a >= d) {
				return 0;
			}
			else {
				return 3;
			}
		}
		else {
			if (c >= d) {
				return 2;
			}
			else {
				return 3;
			}
		}
	}
	else {
		if (b >= c) {
			if (b >= d) {
				return 1;
			}
			else {
				return 3;
			}
		}
		else {
			if (c >= d) {
				return 2;
			}
			else {
				return 3;
			}
		}
	}
}

int main(void) {
	int si, sj;

	vector<vector<int>> t(50, vector<int>(50));
	vector<vector<int>> p(50, vector<int>(50));

	cin >> si >> sj;

	for (int i = 0; i < 50; ++i) {
		for (int j = 0; j < 50; ++j) {
			cin >> t[i][j];
		}
	}
	for (int i = 0; i < 50; ++i) {
		for (int j = 0; j < 50; ++j) {
			cin >> p[i][j];
		}
	}

	int c;

	for (;;) {

		int up = -1;
		int down = -1;
		int left = -1;
		int right = -1;

		if (si > 0 && t[si][sj] != t[si - 1][sj]) {
			up = p[si - 1][sj];
		}
		if (si < 49 && t[si][sj] != t[si + 1][sj]) {
			down = p[si + 1][sj];
		}
		if (sj > 0 && t[si][sj] != t[si][sj - 1]) {
			left = p[si][sj - 1];
		}
		if (sj < 49 && t[si][sj] != t[si][sj + 1]) {
			right = p[si][sj + 1];
		}

		int m = func(up, down, left, right);

		if (up == -1 && down == -1 && left == -1 && right == -1) {
			return 0;
		}

		c = t[si][sj];

		if (m == 0) {
			cout << "U";
			--si;
		}
		else if (m == 1) {
			cout << "D";
			++si;
		}
		else if (m == 2) {
			cout << "L";
			--sj;
		}
		else if (m == 3) {
			cout << "R";
			++sj;
		}

		int c2 = t[si][sj];

		if (si > 0 && c2 == t[si - 1][sj]) {
			t[si - 1][sj] = c;
		}
		if (si < 49 && c2 == t[si + 1][sj]) {
			t[si + 1][sj] = c;
		}
		if (sj > 0 && c2 == t[si][sj - 1]) {
			t[si][sj - 1] = c;
		}
		if (sj < 49 && c2 == t[si][sj + 1]) {
			t[si][sj + 1] = c;
		}

		t[si][sj] = c;

	}

	return 0;
}
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
using namespace std;

#define FIO                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define mp make_pair
#define fi first
#define se second
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) (((a) * (b)) / (__gcd((a), (b))))
#define in_range(x, y, r, c) (x < r && y < c && x >= 0 && y >= 0)
#define setbits(x) __builtin_popcountll(x)
#define unsetend(x) __builtin_ctzll(x)
#define unsetfront(x) __builtin_clzll(x)
#define f first
#define s second
#define pb push_back
#define pf push_front
#define ll long long
#define all(a) a.begin(), a.end()
#define sd(x) scanf("%d", &x) // to use this make sure to remove ios_base....
#define sll(x) scanf("%lld", &x)
#define endl "\n"
#define Endl "\n"
#define INF INT_MAX

long long expo(long long a, long long b, long long m)
{
    ll ret = 1;
    while (b > 0)
    {
        if (b % 2 == 1)
            ret = ((ret % m) * (a % m)) % m;

        a = (a % m) * (a % m);
        b = b / 2;
    }
    return ret;
}

vector<long long> seive()
{
    long long i, j;
    vector<long long> hash(1000001, 1);
    vector<long long> primes;

    for (i = 2; i * i <= 1000000; i++)
    {
        if (hash[i])
        {
            for (j = i * i; j <= 1000000; j += i)
                hash[j] = 0;
        }
    }
    for (i = 2; i < 1000001; i++)
    {
        if (hash[i])
            primes.pb(i);
    }
    return primes;
}

int main()
{
    FIO;
    int n, m;
    cin >> n >> m;
    int mod = 1e9 + 7;
    char arr[n][m];
    int dp[n][m];
    int dpup[n][m];
    int dpleft[n][m];
    int dpdiag[n][m];
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> arr[i][j];
            dp[i][j] = 0;
            dpup[i][j] = 0;
            dpleft[i][j] = 0;
            dpdiag[i][j] = 0;
        }
    }
    dp[0][0] = 1;
    dpleft[0][0] = 1;
    dpup[0][0] = 1;
    dpdiag[0][0] = 1;

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (i == 0 && j == 0)
                continue;
            if (arr[i][j] == '.')
            {
                int a = 0, b = 0, c = 0;
                if (i - 1 >= 0)
                    a = dpup[i - 1][j];
                if (j - 1 >= 0)
                    b = dpleft[i][j - 1];
                if (i - 1 >= 0 && j - 1 >= 0)
                    c = dpdiag[i - 1][j - 1];

                dp[i][j] = (((a + b) % mod) + c) % mod;
                dpup[i][j] = (dp[i][j] + a) % mod;
                dpleft[i][j] = (dp[i][j] + b) % mod;
                dpdiag[i][j] = (dp[i][j] + c) % mod;
            }
        }
    }
    // for (int i = 0; i < n; i++)
    // {
    //     for (int j = 0; j < m; j++)
    //         cout << dp[i][j] << " ";
    //     cout << endl;
    // }
    cout << dp[n - 1][m - 1] << endl;
}
