#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define F first
#define S second

// Bin search on ans?  / DP ? what pattern : greedy / bit manipulation / graph ? dfs or bfs or pattern ? DSU //
// Heap ? two heaps ? / Stack ? monotonic stack /deque ? //
// If divide & conquer - merge sort / check for quick sort implementation as well 

/* ---------------------------------------------------------------------------------------------------------------------------- */

int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
string dirn = "RUDL";

bool isPossible(int x, int y, vector<string>& grid,vector<vector<bool>>& vis){
    int n = grid.size(), m = grid[0].size();
    if(x >= n || x < 0 || y >= m || y < 0 || grid[x][y] == '#' || vis[x][y]) return false;
    return true;
}

void solve(){
    int n,m;
    cin>>n>>m;
    vector<string> grid(n);
    for(int i = 0;i<n;i++)
        cin>>grid[i];
    
    queue<pair<int,int>> mon_q;
    pair<int,int> start;
    vector<vector<int>> mon_t(n,vector<int>(m,-1));
    vector<vector<bool>> vis(n,vector<bool>(m,false));

    for(int i = 0;i<n;i++){
        for(int j = 0;j<m;j++){
            if(grid[i][j] == 'M'){
                mon_q.push({i,j});
                mon_t[i][j] = 0;
            }
            if(grid[i][j] == 'A') {
                start.F = i, start.S = j;      // storing my initial location 
            }
        }
    }

    int cnt = 1;

    //Multi-Source BFS

    while(!mon_q.empty()){
        int grid_size = sz(mon_q);
        for(int i = 0;i<grid_size;i++){
            auto temp = mon_q.front();
            int x = temp.F, y = temp.S;
            mon_q.pop();
            for(int k = 0;k<4;k++){
                int nx = x + dx[k], ny = y + dy[k];
                if(isPossible(nx,ny,grid,vis)){
                    mon_t[nx][ny] = cnt;
                    vis[nx][ny] = true;
                    mon_q.push({nx,ny});
                }
            }
        }
        cnt++;
    }

    //----------------------------------------//

    cnt = 1;
    
    vis.resize(n,vector<bool>(m,false));
    vector<vector<int>> path(n,vector<int>(m,-1));
    queue<pair<int,int>> q;

    q.push(start);

    while(!q.empty()){
        auto temp = q.front();
        int x = temp.F, y = temp.S;
        q.pop();
        vis[x][y] = true;

        for(int k = 0;k<4;k++){
            int nx = x + dx[k], ny = y + dy[k];
            if(isPossible(nx,ny,grid,vis)){
                if(cnt < mon_t[nx][ny]){
                    path[nx][ny] = k;
                    vis[nx][ny] = true;
                    q.push({nx,ny});

                    // Checking if reached the border... 
                    if(nx == 0 || nx == n-1 || ny == 0 || ny == m-1){
                        cout<<"YES\n";
                        string print_path;

                        pair<int,int> xyz = {nx,ny};
                        while(xyz != start){
                            int idx = path[xyz.F][xyz.S];
                            print_path.push_back(dirn[idx]);
                            idx = 3 - idx;
                            xyz.F += dx[idx];
                            xyz.S += dy[idx];
                        }
                        reverse(all(print_path));
                        cout<<print_path.size()<<"\n";
                        cout<<print_path;

                        return;
                    }
                }
            }
        }
        cnt++;
    }
    cout<<"NO";
}

int main(){
    fast_cin();
    //#ifndef FELIX
        //freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
    //#endif
    ll t = 1;
    //cin >> t;
    for(ll it = 1;it<=t;it++){
        // cout<<"Case #"<<it<<": ";
        solve();
    }
    return 0;
}