/*
“Thank goodness we don't have only serious problems, but ridiculous ones as well.”
Edsger W. Dijkstra
“The existence of problem C(Rokada) cripples the mind; its teaching should, therefore, be regarded as a criminal offense.”
Edsger W. Dijkstra
*/
#include <bits/stdc++.h>
#define maxN 11

using namespace std;

vector <string> s;
int i,j,n,m;

vector<string> resi(int n,int m,vector <string> s){
int x,y,i,j,cnt,tmp;
vector <string> pom;
for(i=0;i<n;i++){
for(j=0;j<m;j++){
    if(s[i][j]>='0' && s[i][j]<='4'){
    cnt=tmp=0;
    if(i>0 && s[i-1][j]=='.') cnt++;
    if(j>0 && s[i][j-1]=='.') cnt++;
    if(i<n-1 && s[i+1][j]=='.') cnt++;
    if(j<m-1 && s[i][j+1]=='.') cnt++;
    if(i>0 && s[i-1][j]=='C') tmp++;
    if(j>0 && s[i][j-1]=='C') tmp++;
    if(i<n-1 && s[i+1][j]=='C') tmp++;
    if(j<m-1 && s[i][j+1]=='C') tmp++;
    if(cnt<(s[i][j]-'0')-tmp || tmp>s[i][j]-'0') {s[0][0]='F'; return s;}
    }
}
}
for(i=0;i<n;i++){
for(j=0;j<m;j++){
    bool b=false;
    if(s[i][j]!='.') continue;
    if(i>0 && s[i-1][j]>='0' && s[i-1][j]<='4') b=true;
    if(i<n-1 && s[i+1][j]>='0' && s[i+1][j]<='4') b=true;
    if(j>0 && s[i][j-1]>='0' && s[i][j-1]<='4') b=true;
    if(j<m-1 && s[i][j+1]>='0' && s[i][j+1]<='4') b=true;
    if(!b) continue;
    pom=s;
    x=i;
    y=j;
    pom[x][y]='C';
    tmp=y+1;
    while(tmp<m){
        if(s[x][tmp]=='#' || (s[x][tmp]>='0' && s[x][tmp]<='4')) break;
        pom[x][tmp]='X';
        tmp++;
    }
    tmp=y-1;
    while(tmp>=0){
        if(s[x][tmp]=='#' || (s[x][tmp]>='0' && s[x][tmp]<='4')) break;
        pom[x][tmp]='X';
        tmp--;
    }
    tmp=x+1;
    while(tmp<n){
        if(s[tmp][y]=='#' || (s[tmp][y]>='0' && s[tmp][y]<='4')) break;
        pom[tmp][y]='X';
        tmp++;
    }
    tmp=x-1;
    while(tmp>=0){
        if(s[tmp][y]=='#' || (s[tmp][y]>='0' && s[tmp][y]<='4')) break;
        pom[tmp][y]='X';
        tmp--;
    }
    pom=resi(n,m,pom);
    if(pom[0][0]!='F') return pom;
}
}
for(i=0;i<n;i++){
for(j=0;j<m;j++){
    if(s[i][j]!='.') continue;
    pom=s;
    x=i;
    y=j;
    pom[x][y]='C';
    tmp=y+1;
    while(tmp<m){
        if(s[x][tmp]=='#' || (s[x][tmp]>='0' && s[x][tmp]<='4')) break;
        pom[x][tmp]='X';
        tmp++;
    }
    tmp=y-1;
    while(tmp>=0){
        if(s[x][tmp]=='#' || (s[x][tmp]>='0' && s[x][tmp]<='4')) break;
        pom[x][tmp]='X';
        tmp--;
    }
    tmp=x+1;
    while(tmp<n){
        if(s[tmp][y]=='#' || (s[tmp][y]>='0' && s[tmp][y]<='4')) break;
        pom[tmp][y]='X';
        tmp++;
    }
    tmp=x-1;
    while(tmp>=0){
        if(s[tmp][y]=='#' || (s[tmp][y]>='0' && s[tmp][y]<='4')) break;
        pom[tmp][y]='X';
        tmp--;
    }
    pom=resi(n,m,pom);
    if(pom[0][0]!='F') return pom;
}
}
if(pom.size()!=0) return pom;
return s;
}

string t;

int main()
{
    cin>>n>>m;
    for(i=0;i<n;i++){
        cin>>t;
        s.push_back(t);
    }
    s=resi(n,m,s);
    if(s[0][0]=='F'){cout<<-1<<endl; return 0;}
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
        if(s[i][j]=='X') s[i][j]='.';
        }
    }
    for(i=0;i<n;i++) cout<<s[i]<<endl;
    return 0;
}