#include<iostream>
#include<stdlib.h>
#include<ctype.h>
using namespace std;
bool check(char **m,int i,int j,int N,int M){
	int br1=0;
			if(m[i][j]=='1'){
			if(i>=1 && m[i-1][j]=='C') br1++;
			if(i<M && m[i+1][j]=='C') br1++;
			if(j-1>=0 && m[i][j-1]=='C') br1++;
			if(j+1<M && m[i][j+1]=='C') br1++;
			if(br1<1) return true;
			br1=0;	
			}
			if(m[i][j]=='2'){
			if(i>=1 && m[i-1][j]=='C') br1++;
			if(i<M && m[i+1][j]=='C') br1++;
			if(j-1>=0 && m[i][j-1]=='C') br1++;
			if(j+1<M && m[i][j+1]=='C') br1++;
			if(br1<2) return true;
			br1=0;	
			}
			if(m[i][j]=='3'){
			if(i>=1 && m[i-1][j]=='C') br1++;
			if(i<M && m[i+1][j]=='C') br1++;
			if(j-1>=0 && m[i][j-1]=='C') br1++;
			if(j+1<M && m[i][j+1]=='C') br1++;
			if(br1<3) return true;
			br1=0;	
			}
			if(m[i][j]=='4'){
			if(i>=1 && m[i-1][j]=='C') br1++;
			if(i<M && m[i+1][j]=='C') br1++;
			if(j-1>=0 && m[i][j-1]=='C') br1++;
			if(j+1<M && m[i][j+1]=='C') br1++;
			if(br1<4) return true;
			br1=0;	
			}
			return false;
}
bool proveribrojeve(char **m,int red,int kolona,int N,int M){
	bool rez1=true,rez2=true,rez3=true,rez4=true,rez=true;
	if(red>=1 && (m[red-1][kolona]=='1' || m[red-1][kolona]=='2' || m[red-1][kolona]=='3' || m[red-1][kolona]=='4')){
		rez1=check(m,red-1,kolona,N,M);
	}
	if(red<N && (m[red+1][kolona]=='1' || m[red+1][kolona]=='2' || m[red+1][kolona]=='3' || m[red+1][kolona]=='4')){
		rez1=check(m,red+1,kolona,N,M);
	}
	if(kolona<N && (m[red][kolona+1]=='1' || m[red][kolona+1]=='2' || m[red][kolona+1]=='3' || m[red][kolona+1]=='4')){
		rez1=check(m,red,kolona+1,N,M);
	}
	if(kolona>=1 && (m[red][kolona-1]=='1' || m[red][kolona-1]=='2' || m[red][kolona-1]=='3' || m[red][kolona-1]=='4')){
		rez1=check(m,red,kolona-1,N,M);
	}
	rez=rez1&&rez2&&rez3&&rez4;
	return rez;
}
bool tarabaprezared(char **m,int red,int maxkolona){
	int j;
	for(j=0;j<maxkolona;j++){
		if(m[red][j]=='#') return true;
	}
	return false;
}
bool tarabaprezakolonu(char **m,int kolona,int maxred){
	int i;
	for(i=0;i<maxred;i++){
		if(m[i][kolona]=='#') return true;
	}
	return false;
}
bool proverired(char **m,int red,int N,int M){
int j;
for(j=0;j<M;j++)
if(m[red][j]=='C')
{if(tarabaprezared(m,red,j)==true) return true;}
else if(tarabaprezared(m,red,j)==false) return false;
return true;
}
bool proverikolonu(char **m,int kolona,int N,int M){
int i;
for(i=0;i<N;i++)
if(m[i][kolona]=='C')
{if(tarabaprezakolonu(m,kolona,i)==true) return true;
else if(tarabaprezakolonu(m,kolona,i)==false) return false;
}
return true;
}
bool proveri(char **m,int N,int M){
	int i,j,brojac=0,br1=0;
	for(i=0;i<N;i++){
		for(i=0;i<M;i++){
			if(m[i][j]=='.') brojac++;
			if(m[i][j]=='1'){
			if(i>=1 && m[i-1][j]=='.') br1++;
			if(i<M && m[i+1][j]=='.') br1++;
			if(j-1>=0 && m[i][j-1]=='.') br1++;
			if(j+1<M && m[i][j+1]=='.') br1++;
			if(br1<1) return false;
			br1=0;	
			}
			if(m[i][j]=='2'){
			if(i>=1 && m[i-1][j]=='.') br1++;
			if(i<M && m[i+1][j]=='.') br1++;
			if(j-1>=0 && m[i][j-1]=='.') br1++;
			if(j+1<M && m[i][j+1]=='.') br1++;
			if(br1<2) return false;
			br1=0;	
			}
			if(m[i][j]=='3'){
			if(i>=1 && m[i-1][j]=='.') br1++;
			if(i<M && m[i+1][j]=='.') br1++;
			if(j-1>=0 && m[i][j-1]=='.') br1++;
			if(j+1<M && m[i][j+1]=='.') br1++;
			if(br1<3) return false;
			br1=0;	
			}
			if(m[i][j]=='4'){
			if(i>=1 && m[i-1][j]=='.') br1++;
			if(i<M && m[i+1][j]=='.') br1++;
			if(j-1>=0 && m[i][j-1]=='.') br1++;
			if(j+1<M && m[i][j+1]=='.') br1++;
			if(br1<4) return false;
			br1=0;	
			}
		}
	}
	if(brojac==0) return false;
	else return true;
}
int main(){
	int N,M,i,j,brojprazna=0,pr=1;
	cin>>N>>M;pr=N*M;
	char **m;
	m=new char *[N];
	for(int i=0;i<N;i++)
	m[i]=new char[M];
	for(i=0;i<N;i++){
		for(j=0;j<M;j++)
	cin>>m[i][j];
	getchar();
	}
	
	for(i=0;i<N;i++)
	for(j=0;j<M;j++)
	{   if(m[i][j]=='.') brojprazna++;
		if(m[i][j]=='0')
		{
			if(i>=1 && m[i-1][j]=='.' ) m[i-1][j]='n';
			if(i<M &&m[i+1][j]=='.' ) m[i+1][j]='n';
			if(j-1>=0 && m[i][j-1]=='.' ) m[i][j-1]='n';
			if(j+1<M && m[i][j+1]=='.' ) m[i][j+1]='n';
		}
		
	}
	/*cout<<"Proba"<<endl;
	for(i=0;i<N;i++){
		for(j=0;j<M;j++)
		cout<<m[i][j];
		cout<<endl;
	}*/
	if(proveri(m,N,M)==false){cout<<"-1";}
	if(proveri(m,N,M)==true){
		if(brojprazna==pr){
			i=0;
			for(j=0;j<M;j++)
			m[i++][j]='C';
			for(i=0;i<N;i++)
			{
				for(j=0;j<M;j++)
				cout<<m[i][j];
				cout<<endl;
			}
			
		}
		if(brojprazna!=pr){
			for(i=0;i<N;i++){
				for(j=0;j<M;j++){
					if(proverired(m,i,N,M)==true && proverikolonu(m,j,N,M)==true && proveribrojeve(m,i,j,N,M)==true)
					m[i][j]='C';
				}
			}
			for(i=0;i<N;i++){
				for(j=0;j<M;j++){
					if(m[i][j]=='n') m[i][j]='.';
					cout<<m[i][j];
				}
				cout<<endl;
			}
		}
	}
}