#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>

using namespace std;

int n, m;
vector<string> grid;
vector<vector<int>> distM, distA;
vector<vector<pair<int, int>>> parent;
vector<vector<char>> dir;

// Direction arrays for Up, Down, Left, Right
int dr[] = {-1, 1, 0, 0};
int dc[] = {0, 0, -1, 1};
char move_dir[] = {'U', 'D', 'L', 'R'};

// Function to check if a cell is valid to move into
bool isValid(int r, int c) {
    return (r >= 0 && r < n && c >= 0 && c < m && grid[r][c] != '#');
}

int main() {
    // Optimize input/output operations
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    if (!(cin >> n >> m)) return 0;

    grid.resize(n);
    distM.assign(n, vector<int>(m, 1e9)); // Initialize with a large number (infinity)
    distA.assign(n, vector<int>(m, 1e9));
    parent.assign(n, vector<pair<int, int>>(m, {-1, -1}));
    dir.assign(n, vector<char>(m, ' '));

    queue<pair<int, int>> qM, qA;
    pair<int, int> startA;

    // Read the grid and find the starting positions of the player and all monsters
    for (int i = 0; i < n; i++) {
        cin >> grid[i];
        for (int j = 0; j < m; j++) {
            if (grid[i][j] == 'M') {
                qM.push({i, j});
                distM[i][j] = 0;
            } else if (grid[i][j] == 'A') {
                startA = {i, j};
                qA.push({i, j});
                distA[i][j] = 0;
            }
        }
    }

    // Step 1: Multi-source BFS for all monsters
    while (!qM.empty()) {
        auto [r, c] = qM.front();
        qM.pop();

        for (int i = 0; i < 4; i++) {
            int nr = r + dr[i];
            int nc = c + dc[i];
            
            // If the cell is valid and hasn't been visited by a monster yet
            if (isValid(nr, nc) && distM[nr][nc] == 1e9) {
                distM[nr][nc] = distM[r][c] + 1;
                qM.push({nr, nc});
            }
        }
    }

    // Step 2: BFS for the Player 'A'
    bool possible = false;
    pair<int, int> end_pos = {-1, -1};

    while (!qA.empty()) {
        auto [r, c] = qA.front();
        qA.pop();

        // If 'A' has reached the boundary of the grid safely
        if (r == 0 || r == n - 1 || c == 0 || c == m - 1) {
            possible = true;
            end_pos = {r, c};
            break;
        }

        for (int i = 0; i < 4; i++) {
            int nr = r + dr[i];
            int nc = c + dc[i];
            
            if (isValid(nr, nc) && distA[nr][nc] == 1e9) {
                // 'A' can only step here if they get there faster than any monster
                if (distA[r][c] + 1 < distM[nr][nc]) {
                    distA[nr][nc] = distA[r][c] + 1;
                    parent[nr][nc] = {r, c};    // Track where we came from
                    dir[nr][nc] = move_dir[i];  // Track what move we made to get here
                    qA.push({nr, nc});
                }
            }
        }
    }

    // Step 3: Print result and reconstruct the path
    if (possible) {
        cout << "YES\n";
        string path = "";
        int r = end_pos.first;
        int c = end_pos.second;

        // Backtrack from the exit to the start point
        while (r != startA.first || c != startA.second) {
            path += dir[r][c];
            auto p = parent[r][c];
            r = p.first;
            c = p.second;
        }
        
        // Reverse the path since we built it backwards
        reverse(path.begin(), path.end());
        cout << path.length() << "\n";
        cout << path << "\n";
    } else {
        cout << "NO\n";
    }

    return 0;
}