using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace zadatak_pozar
{
    internal class Program
    {
        static void ch(ref char[,] r, ref bool[,] x, int i, int j, int n, int m, char o)
        {
            if (i - 1 >= 0)
            {
                if (r[i - 1, j] == '.')
                {
                    r[i - 1, j] = o;
                    x[i - 1, j] = true;
                }
            }
            if (i + 1 < n)
            {
                if (r[i + 1, j] == '.')
                {
                    r[i + 1, j] = o;
                    x[i + 1, j] = true;
                }
            }
            if (j - 1 >= 0)
            {
                if (r[i, j - 1] == '.')
                {
                    r[i, j - 1] = o;
                    x[i, j - 1] = true;
                }
            }
            if (j + 1 < m)
            {
                if (r[i, j + 1] == '.')
                {
                    r[i, j + 1] = o;
                    x[i, j + 1] = true;
                }
            }
        }
        static void Main(string[] args)
        {
            string[] unos = Console.ReadLine().Split();
            int n = int.Parse(unos[0]);
            int m = int.Parse(unos[1]);
            char[,] p = new char[n, m];
            bool[,] x = new bool[n, m];
            bool[,] y = new bool[n, m];
            for (int i = 0; i < n; i++)
            {
                string unosa = Console.ReadLine();
                for (int j = 0; j < m; j++)
                {
                    p[i, j] = unosa[j];
                    x[i, j] = false;
                }
            }
            bool g = true;
            int s = 0;

           
            do
            {
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < m; j++)
                    {
                        if (p[i, j] == 'X' && x[i,j]==false)
                        {
                            ch(ref p, ref x, i, j, n, m, 'X');
                            x[i, j] = true;
                        }
                        else if (p[i, j] == 'S' && s<2)
                        {
                            ch(ref p,ref y, i, j, n, m, 'S');
                            s++;
                        }
                    }
                }
                s = 0;
                g = false;
                foreach (char c in p)
                {
                    if (c == '.')
                    {
                        g = true;
                    }
                }
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < m; j++)
                    {
                        x[i, j] = false;
                    }
                }

            } while (g);
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    Console.Write(p[i, j] + " ");
                }
                Console.Write('\n');
            }
        }
    }
}