#include <iostream>
#include <vector>
#include <tuple>

using namespace std;

int N,M;
bool mj=true;

int Func(char Mat[12][12],vector<tuple<int,int,int>> Q, char Mat2[12][12]);

int CleanZ(char Mat[12][12]);

bool inArea(int x,int y)
{
    return x>=0 && y>=0 && x<N && y<M;
}

void MarkC(int x,int y,char Mat2[12][12])
{
    bool xp=true,yp=true,xm=true,ym=true;
    int  p=1;
    while(xp||yp||xm||ym)
    {
        if(xp && inArea(x+p,y))
        {
            if(Mat2[x+p][y]=='.' || Mat2[x+p][y]=='X' || Mat2[x+p][y]=='*'){Mat2[x+p][y]='X';}
            else{xp=false;}
        }
        else{xp=false;}
        if(xm && inArea(x-p,y))
        {
            if(Mat2[x-p][y]=='.' || Mat2[x-p][y]=='X' || Mat2[x-p][y]=='*'){Mat2[x-p][y]='X';}
            else{xm=false;}
        }
        else{xm=false;}
        if(yp && inArea(x,y+p))
        {
            if(Mat2[x][y+p]=='.' || Mat2[x][y+p]=='X' || Mat2[x][y+p]=='*'){Mat2[x][y+p]='X';}
            else{yp=false;}
        }
        else{yp=false;}
        if(ym && inArea(x,y-p))
        {
            if(Mat2[x][y-p]=='.' || Mat2[x][y-p]=='X' || Mat2[x][y-p]=='*'){Mat2[x][y-p]='X';}
            else{ym=false;}
        }
        else{ym=false;}
        p++;
    }
}

bool SpanZ(int x,int y,char Mat2[12][12])
{
    bool xp=true,yp=true,xm=true,ym=true;
    int  p=1;
    char Mat3[12][12];
    while(xp||yp||xm||ym)
    {
        if(xp && inArea(x+p,y))
        {
            if(Mat2[x+p][y]=='.')
            {
               for(int i=0;i<N;i++)
                {
                    for(int j=0;j<M;j++)
                    {
                        Mat3[i][j]=Mat2[i][j];
                    }
                }
                Mat3[x+p][y]='C';MarkC(x+p,y,Mat3);
                CleanZ(Mat3);
            }
            else if(Mat2[x+p][y]=='X' || Mat2[x+p][y]=='*'){}
            else{xp=false;}
        }
        else{xp=false;}
        if(xm && inArea(x-p,y))
        {
            if(Mat2[x-p][y]=='.')
            {
               for(int i=0;i<N;i++)
                {
                    for(int j=0;j<M;j++)
                    {
                        Mat3[i][j]=Mat2[i][j];
                    }
                }
                Mat3[x-p][y]='C';MarkC(x-p,y,Mat3);
                CleanZ(Mat3);
            }
            else if(Mat2[x-p][y]=='X' || Mat2[x-p][y]=='*'){}
            else{xm=false;}
        }
        else{xm=false;}
        if(yp && inArea(x,y+p))
        {
            if(Mat2[x][y+p]=='.')
            {
               for(int i=0;i<N;i++)
                {
                    for(int j=0;j<M;j++)
                    {
                        Mat3[i][j]=Mat2[i][j];
                    }
                }
                Mat3[x][y+p]='C';MarkC(x,y+p,Mat3);
                CleanZ(Mat3);
            }
            else if(Mat2[x][y+p]=='X' || Mat2[x][y+p]=='*'){}
            else{yp=false;}
        }
        else{yp=false;}
        if(ym && inArea(x,y-p))
        {
            if(Mat2[x][y-p]=='.')
            {
               for(int i=0;i<N;i++)
                {
                    for(int j=0;j<M;j++)
                    {
                        Mat3[i][j]=Mat2[i][j];
                    }
                }
                Mat3[x][y-p]='C';MarkC(x,y-p,Mat3);
                CleanZ(Mat3);
            }
            else if(Mat2[x][y-p]=='X' || Mat2[x][y-p]=='*'){}
            else{ym=false;}
        }
        else{ym=false;}
        p++;
    }
    return false;
}

int CountCannons(int x,int y,char Mat2[12][12])
{
    int br=0;
    if(inArea(x+1,y) && Mat2[x+1][y]=='C'){br++;}
    if(inArea(x-1,y) && Mat2[x-1][y]=='C'){br++;}
    if(inArea(x,y+1) && Mat2[x][y+1]=='C'){br++;}
    if(inArea(x,y-1) && Mat2[x][y-1]=='C'){br++;}
    return br;
}

int CountFree(int x,int y,char Mat2[12][12])
{
    int br=0;
    if(inArea(x+1,y) && Mat2[x+1][y]=='.'){br++;}
    if(inArea(x-1,y) && Mat2[x-1][y]=='.'){br++;}
    if(inArea(x,y+1) && Mat2[x][y+1]=='.'){br++;}
    if(inArea(x,y-1) && Mat2[x][y-1]=='.'){br++;}
    return br;
}

int main()
{
    char Mat[12][12];
    char RMat[12][12];
    char RMat2[12][12];
    vector<tuple<int,int,int>> Q2;
    cin>>N>>M;
    for(int i=0;i<N;i++)
    {
        char line[12];
        cin>>line;
        for(int j=0;j<M;j++)
        {
            Mat[i][j] = line[j];
            switch(line[j])
            {
                case '0':{}
                case '1':{}
                case '2':{}
                case '3':{}
                case '4':{Q2.push_back(make_tuple(line[j]-'0',i,j)); break;}
                default:{break;}
            }
        }
    }

    int r=Func(Mat,Q2,RMat);

    if(r==-1){cout<<-1;}
    else
    {
        CleanZ(RMat);
        if(mj){cout<<-1;}
    }

    return 0;
}

int CleanZ(char Mat[12][12])
{
    char Mat2[12][12];
    bool b=true;
    for(int i=0;i<N;i++)
    {
        for(int j=0;j<M;j++)
        {
            Mat2[i][j]=Mat[i][j];
        }
    }

    for(int i=0;i<N;i++)
    {
        for(int j=0;j<M;j++)
        {
            if(Mat2[i][j]=='*'){SpanZ(i,j,Mat2);goto fe;}
        }
    }

    if(b){
        mj=false;
        for(int i=0;i<N;i++)
        {
            for(int j=0;j<M;j++)
            {
                if(Mat2[i][j]=='.'){Mat2[i][j]=='C';MarkC(i,j,Mat2);}
            }
        }
        for(int i=0;i<N;i++)
        {
            for(int j=0;j<M;j++)
            {
                if(Mat2[i][j]=='X'){cout<<'.';}
                else{cout<<Mat2[i][j];}
            }
            cout<<endl;
        }
    }
    fe:;
}

int Func(char Mat[12][12],vector<tuple<int,int,int>> Q, char Mat2[12][12])
{
    for(int i=0;i<N;i++)
    {
        for(int j=0;j<M;j++)
        {
            Mat2[i][j]=Mat[i][j];
        }
    }
    bool flunked=false;
    while(!Q.empty())
    {   int c=0;
        for(int i=0;i<Q.size();i++)
        {
            int m=get<0>(Q[i]),x=get<1>(Q[i]),y=get<2>(Q[i]);
            if(m==0)
            {
                if(inArea(x+1,y) && Mat2[x+1][y]=='.'){Mat2[x+1][y]='*';}
                if(inArea(x-1,y) && Mat2[x-1][y]=='.'){Mat2[x-1][y]='*';}
                if(inArea(x,y+1) && Mat2[x][y+1]=='.'){Mat2[x][y+1]='*';}
                if(inArea(x,y-1) && Mat2[x][y-1]=='.'){Mat2[x][y-1]='*';}
                Q.erase(Q.begin()+i);
            }
            else
            {
                if(CountCannons(x,y,Mat2)>m){return -1;}
                else if(CountCannons(x,y,Mat2)==m)
                {
                    if(inArea(x+1,y) && Mat2[x+1][y]=='.'){Mat2[x+1][y]='*';}
                    if(inArea(x-1,y) && Mat2[x-1][y]=='.'){Mat2[x-1][y]='*';}
                    if(inArea(x,y+1) && Mat2[x][y+1]=='.'){Mat2[x][y+1]='*';}
                    if(inArea(x,y-1) && Mat2[x][y-1]=='.'){Mat2[x][y-1]='*';}
                    Q.erase(Q.begin()+i);
                }
                else if(CountCannons(x,y,Mat2)+CountFree(x,y,Mat2)<m){return -1;}
                else if(CountCannons(x,y,Mat2)+CountFree(x,y,Mat2)==m)
                {
                    if(inArea(x+1,y) && Mat2[x+1][y]=='.'){Mat2[x+1][y]='C';MarkC(x+1,y,Mat2);}
                    if(inArea(x-1,y) && Mat2[x-1][y]=='.'){Mat2[x-1][y]='C';MarkC(x-1,y,Mat2);}
                    if(inArea(x,y+1) && Mat2[x][y+1]=='.'){Mat2[x][y+1]='C';MarkC(x,y+1,Mat2);}
                    if(inArea(x,y-1) && Mat2[x][y-1]=='.'){Mat2[x][y-1]='C';MarkC(x,y-1,Mat2);}
                    Q.erase(Q.begin()+i);
                }
                else{c++;}
            }
        }
        if(c>0 && c==Q.size()){flunked=true;break;}
    }

    if(flunked==true)
    {
        char Mat3[12][12];
        char RMat[12][12];
        int m=get<0>(Q[0]),x=get<1>(Q[0]),y=get<2>(Q[0]);

        for(int i=0;i<N;i++)
        {
            for(int j=0;j<M;j++)
            {
                Mat3[i][j]=Mat2[i][j];
            }
        }
        if(inArea(x+1,y) && Mat3[x+1][y]=='.'){Mat3[x+1][y]='C';MarkC(x+1,y,Mat3); int r=Func(Mat3,Q,RMat);
            if(r==0){
                for(int i=0;i<N;i++)
                {
                    for(int j=0;j<M;j++)
                    {
                        Mat2[i][j]=RMat[i][j];
                    }
                }
                return 0;
            }
        }

        for(int i=0;i<N;i++)
        {
            for(int j=0;j<M;j++)
            {
                Mat3[i][j]=Mat2[i][j];
            }
        }
        if(inArea(x-1,y) && Mat3[x-1][y]=='.'){Mat3[x-1][y]='C';MarkC(x-1,y,Mat3);int r=Func(Mat3,Q,RMat);
            if(r==0){
                for(int i=0;i<N;i++)
                {
                    for(int j=0;j<M;j++)
                    {
                        Mat2[i][j]=RMat[i][j];
                    }
                }
                return 0;
            }
        }

        for(int i=0;i<N;i++)
        {
            for(int j=0;j<M;j++)
            {
                Mat3[i][j]=Mat2[i][j];
            }
        }
        if(inArea(x,y+1) && Mat3[x][y+1]=='.'){Mat3[x][y+1]='C';MarkC(x,y+1,Mat3);int r=Func(Mat3,Q,RMat);
            if(r==0){
                for(int i=0;i<N;i++)
                {
                    for(int j=0;j<M;j++)
                    {
                        Mat2[i][j]=RMat[i][j];
                    }
                }
                return 0;
            }
        }

        for(int i=0;i<N;i++)
        {
            for(int j=0;j<M;j++)
            {
                Mat3[i][j]=Mat2[i][j];
            }
        }
        if(inArea(x,y-1) && Mat3[x][y-1]=='.'){Mat3[x][y-1]='C';MarkC(x,y-1,Mat3);int r=Func(Mat3,Q,RMat);
            if(r==0){
                for(int i=0;i<N;i++)
                {
                    for(int j=0;j<M;j++)
                    {
                        Mat2[i][j]=RMat[i][j];
                    }
                }
                return 0;
            }
        }

        return -1;
    }
    else
    {
        return 0;
    }
}