#include<bits/stdc++.h>
#define int long long
using namespace std;
int cha[1001][1001];
char a[1001][1001];
int dx[4]={-1,1,0,0};
int dy[4]={0,0,-1,1};
char huong[4]={'U','D','L','R'};
int n,m,a1,a2;
string cc="";
signed main()
{
queue<pair<int,int>>q;
cin>>n>>m;
for (int i=1;i<=n;i++)
{
for (int j=1;j<=m;j++)
{
cin>>a[i][j];
if (a[i][j]=='M')
{
q.push({i,j});
}
else if (a[i][j]=='A')
{
a1=i;
a2=j;
}
}
}
q.push({a1,a2});
while (!q.empty())
{
int x=q.front().first;
int y=q.front().second;
q.pop();
if (a[x][y]=='A'&&(x==1||x==n||y==1||y==m))
{
cout<<"YES"<<"\n";
while (x!=a1||y!=a2)
{
int k=cha[x][y];
cc=huong[k]+cc;
x=x-dx[k];
y=y-dy[k];
}
cout<<cc.size()<<"\n";
cout<<cc;
return 0;
}
for (int i=0;i<4;i++)
{
int xx=x+dx[i];
int yy=y+dy[i];
if (xx>=1&&xx<=n&&yy>=1&&yy<=m&&a[xx][yy]=='.')
{
a[xx][yy]=a[x][y];
if (a[xx][yy]=='A') cha[xx][yy]=i;
q.push({xx,yy});
}
}
}
cout<<"NO";
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBpbnQgbG9uZyBsb25nCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBjaGFbMTAwMV1bMTAwMV07CmNoYXIgYVsxMDAxXVsxMDAxXTsKaW50IGR4WzRdPXstMSwxLDAsMH07CmludCBkeVs0XT17MCwwLC0xLDF9OwpjaGFyIGh1b25nWzRdPXsnVScsJ0QnLCdMJywnUid9OwppbnQgbixtLGExLGEyOwpzdHJpbmcgY2M9IiI7CnNpZ25lZCBtYWluKCkKewoKICAgIHF1ZXVlPHBhaXI8aW50LGludD4+cTsKICAgIGNpbj4+bj4+bTsKICAgIGZvciAoaW50IGk9MTtpPD1uO2krKykKICAgIHsKICAgICAgICBmb3IgKGludCBqPTE7ajw9bTtqKyspCiAgICAgICAgewogICAgICAgICAgICBjaW4+PmFbaV1bal07CiAgICAgICAgICAgIGlmIChhW2ldW2pdPT0nTScpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHEucHVzaCh7aSxqfSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZSBpZiAoYVtpXVtqXT09J0EnKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBhMT1pOwogICAgICAgICAgICAgICAgYTI9ajsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KICAgIHEucHVzaCh7YTEsYTJ9KTsKICAgIHdoaWxlICghcS5lbXB0eSgpKQogICAgewogICAgICAgIGludCB4PXEuZnJvbnQoKS5maXJzdDsKICAgICAgICBpbnQgeT1xLmZyb250KCkuc2Vjb25kOwogICAgICAgIHEucG9wKCk7CiAgICAgICAgaWYgKGFbeF1beV09PSdBJyYmKHg9PTF8fHg9PW58fHk9PTF8fHk9PW0pKQogICAgICAgIHsKICAgICAgICAgICAgY291dDw8IllFUyI8PCJcbiI7CiAgICAgICAgICAgIHdoaWxlICh4IT1hMXx8eSE9YTIpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGludCBrPWNoYVt4XVt5XTsKICAgICAgICAgICAgICAgIGNjPWh1b25nW2tdK2NjOwogICAgICAgICAgICAgICAgeD14LWR4W2tdOwogICAgICAgICAgICAgICAgeT15LWR5W2tdOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGNvdXQ8PGNjLnNpemUoKTw8IlxuIjsKICAgICAgICAgICAgY291dDw8Y2M7CiAgICAgICAgICAgIHJldHVybiAwOwogICAgICAgIH0KICAgICAgICBmb3IgKGludCBpPTA7aTw0O2krKykKICAgICAgICB7CiAgICAgICAgICAgIGludCB4eD14K2R4W2ldOwogICAgICAgICAgICBpbnQgeXk9eStkeVtpXTsKICAgICAgICAgICAgaWYgKHh4Pj0xJiZ4eDw9biYmeXk+PTEmJnl5PD1tJiZhW3h4XVt5eV09PScuJykKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgYVt4eF1beXldPWFbeF1beV07CiAgICAgICAgICAgICAgICBpZiAoYVt4eF1beXldPT0nQScpIGNoYVt4eF1beXldPWk7CiAgICAgICAgICAgICAgICBxLnB1c2goe3h4LHl5fSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICBjb3V0PDwiTk8iOwogICAgcmV0dXJuIDA7Cn0K