#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","U","D"};
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;	
}
