#include<bits/stdc++.h>
using namespace std;
const int MAX = 5001;
char path[MAX][MAX];
vector<vector<int> > valid(MAX,vector<int>(MAX,0));
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};
string moves[] = {"L","R","D","U"};
int n,m;
bool is_sol(pair<int,int> point){
return point.first == 0 || point.first == n-1
|| point.second == 0 || point.second == m-1;
}
bool check(pair<int,int> p){
if(p.first<0 || p.second<0 || valid[p.first][p.second] ||
p.first>=n || p.second>=m || path[p.first][p.second]!='.') return false;
return true;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
queue<pair<int,int> > pq_; //this is for monsters..
queue<pair<pair<int,int>,string> > pq; // this is for the player...
cin>>n>>m;
for(int i = 0;i<n;i++)
for(int j = 0;j<m;j++){
cin>>path[i][j];
if(path[i][j]=='.') valid[i][j] = 1;
else if(path[i][j] == 'A') pq.push({{i,j},""});
else if(path[i][j] == 'M') pq_.push({i,j});
}
while(!pq.empty()){
pair<int,int> p = pq_.front();
pq_.pop();
for(int i = 0;i<4;i++){
int xx_ = p.first + dx[i];
int yy_ = p.second + dy[i];
if(check(make_pair(xx_,yy_)))
{
pq_.push({xx_,yy_}); valid[xx_][yy_] = 0;
}
}
pair<pair<int,int>,string> q = pq.front();
pq.pop();
string s = q.second;
if(is_sol({q.first.first,q.first.second})){
cout<<"YES"<<'\n'<<s.length()<<'\n';
cout<<s<<'\n';
return 0;
}
for(int i = 0;i<4;i++){
int xx_ = q.first.first + dx[i];
int yy_ = q.first.second + dy[i];
if(check(make_pair(xx_,yy_)))
{
pq.push({{xx_,yy_},s + moves[i]}); valid[xx_][yy_] = 0;
}
}
}
cout<<"NO"<<'\n';
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKY29uc3QgaW50IE1BWCA9IDUwMDE7CmNoYXIgcGF0aFtNQVhdW01BWF07CnZlY3Rvcjx2ZWN0b3I8aW50PiA+IHZhbGlkKE1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