import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Set;
import java.util.HashSet;
import java.util.HashMap;
import java.util.Queue;
import java.util.LinkedList;
import java.util.StringTokenizer;

/* A runner captured in a maze needs your help. Your goal is to find the shortest
 * way through the maze from the runner's initial position to the exit.
 *
 * The maze is build out of walls ('#'), corridors (' '), and exit ('E').
 * You may assume the maze is enclosed by walls (including 'E').
 */
public class mazerunner
{
    /* The directions in which the maze runner can move. */
    public static final int[][] DIRECTIONS = new int[][]{{-1, 0},{1, 0},{0, -1},{0, 1}};

    /* The representation of a state of the world. */
    public static class QueueState
    {
        public int x;        // Runner's x position in the world.
        public int y;        // Runner's y position in the world.

        /* Returns a hash code (in fact a unique Id) for this state. */
        @Override
        public int hashCode()
        {
            return (this.x << 16) + this.y;
        }

        /* This is definitely not the right way to override this method
         * but (!) we know what we are doing. */
        @Override
        public boolean equals(Object other)
        {
            return (this.x == ((QueueState)other).x && this.y == ((QueueState)other).y);
        }

        /* Returns a new state which was created from this state
         * by moving the runner in the specified direction.
         */
        public QueueState move(int[] direction)
        {
            QueueState copy = new QueueState();

            copy.x = this.x + direction[0];
            copy.y = this.y + direction[1];

            return copy;
        }
    }

    /* Stores the map read from the input. */
    public static char[][] map = null;

    /* Keeps track how we got to each (reachable) state. */
    public static HashMap<QueueState, QueueState> predecessor = new HashMap<QueueState, QueueState>();

    /* Indicates whether we have found the state (situation) in the smallest possible time. */
    public static Set<QueueState> resolved = new HashSet<QueueState>();

    /* The queue for bread-first search. */
    public static Queue<QueueState> queue = new LinkedList<QueueState>();

    /* Move the runner from his current position in all directions and try
     * to put the resulting state into the queue. */
    public static void expandState(QueueState prevState)
    {
        for (int[] direction : DIRECTIONS)
        {
            QueueState nextState = prevState.move(direction);

            if (map[nextState.y][nextState.x] != '#')
            {
                if (!resolved.contains(nextState))
                {
                    resolved.add(nextState);

                    queue.add(nextState);

                    /* Remember how we got there. */
                    predecessor.put(nextState, prevState);
                }
            }
        }
    }

    /* Read the map from the standard input and return the state associated
     * with the initial position of the heretic.
     */
    public static QueueState readMap(BufferedReader reader) throws IOException
    {
        String line = null;

        QueueState start = new QueueState();

        int iRow = 0;

        StringTokenizer tokenizer = new StringTokenizer(reader.readLine());

        int width = Integer.valueOf(tokenizer.nextToken());
        int height = Integer.valueOf(tokenizer.nextToken());

        map = new char[height][width];

        while ((line = reader.readLine()) != null)
        {
            int iCol = 0;
                        
            for (int i = 0; i < line.length(); i++)
            {
                map[iRow][iCol] = line.charAt(i);

                if (map[iRow][iCol] == 'R')
                {
                    start.x = iCol;
                    start.y = iRow;
                }

                ++iCol;
            }

            ++iRow;
        }

        return start;
    }

    /* Returns ``true`` only if the heretic stands on the exit from the maze. */
    public static final boolean isFinalState(QueueState state)
    {
        return (map[state.y][state.x] == 'E');
    }

    public static void main(String[] arguments) throws IOException
    {
        /* Read the map from the standard input and get the initial state. */
        QueueState state = readMap(new BufferedReader(new InputStreamReader(System.in)));

        /* Add the initial state into the queue. */
        queue.add(state);
        resolved.add(state);

        /* Until the queue get emptied or a solution has been found. */
        while ((state = queue.poll()) != null && !isFinalState(state))
            expandState(state);

        /* Print out the instructuons or prompt there is no way out. */
        if (state == null)
        {
            System.out.println("There is no way out, arrrgh!");
        }
        else
        {
            state = predecessor.get(state);

            while (predecessor.get(state) != null)
            {
                map[state.y][state.x] = '.';
                state = predecessor.get(state);
            }

            for (char[] row : map)
                System.out.println(row);
        }
    }
}