#include "bits/stdc++.h"
using namespace std;
int sy,sx;
int cell_group[50][50];
int cell_point[50][50];
int dx[]={1,0,-1,0}, dy[]={0,1,0,-1};
string dcoms[]={"R","D","L","U"};
string ans="";
chrono::system_clock::time_point start;
chrono::system_clock::time_point _end;

bool comp(const pair<pair<int,string>,pair<int,int>>& lh, const pair<pair<int,string>,pair<int,int>>& rh) {
     return (lh.first.first+cell_point[lh.second.first][lh.second.second]) < (rh.first.first+cell_point[rh.second.first][rh.second.second]);
}

pair<string,int> dfs(int h, int w, int point, unordered_set<int>& used){
    _end = chrono::system_clock::now();
    double elapsed = chrono::duration_cast<chrono::milliseconds>(_end-start).count();
    if(elapsed>1850){
        string ans_reversed (ans.rbegin(), ans.rend());
        cout<<ans_reversed<<endl;
        exit(0);
    }
    vector<pair<pair<int,string>,pair<int,int>>> target;
    point+=cell_point[h][w];
    for(int i=0;i<4;i++){
        int next_h=h+dy[i],next_w=w+dx[i];
        if(next_h<0 or 50<=next_h or next_w<0 or 50<=next_w) continue;
        if(used.find(cell_group[next_h][next_w])==used.end()){
            target.push_back(make_pair(make_pair(point,dcoms[i]),make_pair(next_h, next_w)));
        }
    }
    if(target.size()==0) return make_pair("", point);
    sort(target.begin(), target.end(), comp);
    
    pair<string,int> fixed_ret=make_pair("", 0);
    
    if(true){
        int j=target.size()-1;
        int next_h=target[j].second.first;
        int next_w=target[j].second.second;
        string dcom=target[j].first.second;
        int tmp_point=target[j].first.first;
        used.emplace(cell_group[next_h][next_w]);
        pair<string,int> ret = dfs(next_h,next_w,tmp_point,used);
        used.erase(cell_group[next_h][next_w]);
        if(fixed_ret.second<ret.second){
            fixed_ret=make_pair(ret.first+dcom,ret.second);
        }
    }

    random_device seed_gen;
    mt19937 engine = mt19937(seed_gen());
    uniform_real_distribution<> dist1(0, 1.0);
    
    if(target.size()>=2 && dist1(engine)<0.15){
        random_device seed_gen;
        mt19937 engine = mt19937(seed_gen());
        uniform_int_distribution<> randint(1,target.size()-1);
        int j=randint(engine);
        
        int next_h=target[j].second.first;
        int next_w=target[j].second.second;
        string dcom=target[j].first.second;
        int tmp_point=target[j].first.first;
        used.emplace(cell_group[next_h][next_w]);
        pair<string,int> ret = dfs(next_h,next_w,tmp_point,used);
        used.erase(cell_group[next_h][next_w]);
        if(fixed_ret.second<ret.second){
            fixed_ret=make_pair(ret.first+dcom,ret.second);
        }
    }
        
    
    return fixed_ret;
}

int main(void){
    start = chrono::system_clock::now();
    
    cin>>sy>>sx;
    for(int i=0;i<50;i++){
        for(int j=0;j<50;j++){
            cin>>cell_group[i][j];
        }
    }
    for(int i=0;i<50;i++){
        for(int j=0;j<50;j++){
            cin>>cell_point[i][j];
        }
    }
    int mx_point=0;
    while(1){
        unordered_set<int> used;
        used.emplace(cell_group[sy][sx]);
        pair<string,int> tmp=dfs(sy,sx,0,used);
        string ans_command=tmp.first;
        int point=tmp.second;
        if(mx_point<point){
            ans=ans_command;
            mx_point=point;
        }
    }
}




#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rng(a) a.begin(),a.end()
using namespace std;
using ll = long long;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};


mint dp[2010][2010];
mint x[2010][2010], y[2010][2010], z[2010][2010];
char s[2010][2010];

int main() {
  int h, w;
  cin >> h >> w;
  rep(i,h) {
    rep(j,w) cin >> s[i][j];
  }
  dp[0][0] = 1;
  rep(i,h) {
    rep(j,w) {
      if(i==0&&j==0) continue;
      if(s[i][j]=='#') continue;
      if(j>0) x[i][j] = x[i][j-1]+dp[i][j-1];
      if(i>0) y[i][j] = y[i-1][j]+dp[i-1][j];
      if(i>0&&j>0) z[i][j] = z[i-1][j-1]+dp[i-1][j-1];
      dp[i][j] = x[i][j]+y[i][j]+z[i][j];
    }
  }
  cout << dp[h-1][w-1].x << endl;
  return 0;
}