#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define D(x) cerr << #x << " is " << (x) << "\n";

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}

int n,m;
vector<string> mat;
vector<int> nxt[3][3][3][3][3][3][3][3][3][3][10]; ///Predhodna je prazna: 0-Nema roocka, 1-Ima rocka ranije,2-Ima rocka odma pre.  Predhodna je broj: 0-Popunjen, 1-Nije popunjen. Predhodna je prepreka: 0-Prepreka :p
vector<int> nxt_pos[3][3][3][3][3][3][3][3][3][3][10];  ///                0              1                   2                                         3           4                                       5
vector<vector<int> > possible,sol;
vector<int> fail={-2};
vector<int> unknown={-1};
vector<int> start;
void gen_all(int i,vector<int> dosada)
{
    if(i==possible.size()){
        sol.pb(dosada);
        return;
    }
    //dosada.pb(-1);
    gen_all(i+1,dosada);
    //dosada.pop_back();
    for(auto p:possible[i])
    {
        dosada.pb(p);
        gen_all(i+1,dosada);
        dosada.pop_back();
    }
}
#define dp nxt[s1][s2][s3][s4][s5][s6][s7][s8][s9][s10][pos]
bool calc(vector<int> state,int pos)
{
    //cout << state << pos << endl;
    int s1=state[0],s2=state[1],s3=state[2],s4=state[3],s5=state[4],s6=state[5],s7=state[6],s8=state[7],s9=state[8],s10=state[9];
    if(dp!=unknown)
    {
        if(dp==fail)
            return false;
        return true;
    }
    //printf("Ovde!\n");
    for(int i=0;i<m;i++)
    {
        if(pos==0)
        {
            assert(state[i]==0);
            state[i]=5;
        }
        else
        {
            if(mat[pos-1][i]=='.')
            {

            }
            else
            {
                if(mat[pos-1][i]=='#')
                {
                    state[i]=5;
                }
                else
                {
                    state[i]+=3;
                }
            }
        }
    }
    vector<int> covered(m);
    for(int i=0;i<m;i++)
    {
        if(state[i]==2)
        {
            int tr=i;
            while(tr>=0&&mat[pos-1][tr]=='.')
            {
                if((pos>1&&mat[pos-2][tr]!='.')||pos<2)
                    covered[tr]=1;
                tr--;
            }
            tr=i;
            while(tr<m&&mat[pos-1][tr]=='.')
            {
                if((pos>1&&mat[pos-2][tr]!='.')||pos<2)
                    covered[tr]=1;
                tr++;
            }
        }
    }
    if(pos==n)
    {
        for(int i=0;i<m;i++)
        {
            if((state[i]==0&&covered[i]==0)||state[i]==4)
                return false;
        }
        return true;
    }
    //printf("Ovde!\n");
    possible.clear();
    sol.clear();
    possible.pb(start);
    for(int i=0;i<m;i++)
    {
        if(mat[pos][i]!='.')
        {
            if(possible.back().size()>0)
                possible.pb(start);
        }
        else
        {
            if(state[i]==0||state[i]==4||state[i]==5)
                possible.back().pb(i);
        }
    }
    if(possible.back().size()==0)
        possible.pop_back();
    //cout << possible;
    //printf("GEN!\n");
    gen_all(0,start);
    //cout << sol << endl;
    vector<vector<int> > ss=sol;
    for(auto p:ss)
    {
        //cout << "Gledam " << p << endl;
        vector<int> uzimam(m);
        for(auto d:p)
            uzimam[d]=1;
        string tr=mat[pos];
        bool t=true;
        for(int i=0;i<m;i++)
        {
            if(mat[pos][i]=='.')
            {
                if(uzimam[i])
                {
                    assert(state[i]==0||state[i]==4||state[i]==5);
                    tr[i]='C';
                }
                else
                {
                    if(state[i]==4)
                    {
                        //printf("fail1\n");
                        t=false;
                        break;
                    }
                }
            }
            else
            {
                if((state[i]==0&&covered[i]==0)||state[i]==4)
                {
                    //printf("fail2 %i\n",i);
                    t=false;
                    break;
                }
                assert(uzimam[i]==0);
                if(mat[pos][i]=='#')
                {
                }
                else
                {
                    if(state[i]==2)
                        tr[i]--;
                    if(i>0&&uzimam[i-1]==1)
                        tr[i]--;
                    if(i<m-1&&uzimam[i+1]==1)
                        tr[i]--;
                    if(tr[i]<'0'||tr[i]>'1')
                    {
                        //printf("fail3\n");
                        t=false;
                        break;
                    }
                }
            }
        }
        if(!t)
            continue;
        vector<int> next_state(10);
        for(int i=0;i<m;i++)
        {
            if(tr[i]=='C')
            {
                assert(state[i]==0||state[i]==4||state[i]==5);
                assert(mat[pos][i]=='.');
                next_state[i]=2;
            }
            if(tr[i]=='.')
            {
                if(state[i]==0||state[i]==3||state[i]==5)
                    next_state[i]=0;
                if(state[i]==1||state[i]==2)
                    next_state[i]=1;
                if(state[i]==4)
                {
                    t=false;
                    break;
                }
            }
            if(tr[i]=='#')
            {
                next_state[i]=0;
            }
            if(tr[i]=='0')
            {
                next_state[i]=0;
            }
            if(tr[i]=='1')
            {
                next_state[i]=1;
            }
        }
        if(!t)
            continue;
        if(calc(next_state,pos+1))
        {
            dp=p;
            nxt_pos[s1][s2][s3][s4][s5][s6][s7][s8][s9][s10][pos]=next_state;
            return true;
        }
    }
    //printf("FAIL!\n");
    dp=fail;
    return false;
}
int main()
{
    for(int s1=0;s1<3;s1++)
        for(int s2=0;s2<3;s2++)
            for(int s3=0;s3<3;s3++)
                for(int s4=0;s4<3;s4++)
                for(int s5=0;s5<3;s5++)
                for(int s6=0;s6<3;s6++)
                for(int s7=0;s7<3;s7++)
                for(int s8=0;s8<3;s8++)
                for(int s9=0;s9<3;s9++)
                for(int s10=0;s10<3;s10++)
                for(int pos=0;pos<10;pos++)
                dp=unknown;
	scanf("%i %i",&n,&m);
	mat.resize(n);
	for(int i=0;i<n;i++)
        cin >> mat[i];
    vector<int> state(10,0);
    bool bo=calc(state,0);
    if(!bo)
    {
        printf("-1\n");
        return 0;
    }
    int a=0,b=0;
    for(int i=0;i<n;i++)
    {
        int s1=state[0],s2=state[1],s3=state[2],s4=state[3],s5=state[4],s6=state[5],s7=state[6],s8=state[7],s9=state[8],s10=state[9];
        for(auto p:nxt[s1][s2][s3][s4][s5][s6][s7][s8][s9][s10][i])
            mat[i][p]='C';
        state=nxt_pos[s1][s2][s3][s4][s5][s6][s7][s8][s9][s10][i];
    }
    for(int i=0;i<n;i++)
        cout << mat[i] << endl;
    return 0;
}