#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
string s;
int n,m,tacka_cnt,rez,glcnt;
int idx[4]={0,0,1,-1};
int idy[4]={1,-1,0,0};
char a[20][20];
bool pos[20][20];
bool cifra(char pom){
   if(pom>='0' && pom<='4')return 1;
   else return 0;
}
int c_count(int i,int j){
  int cnt=0;
  for(int k=0;k<=3;k++)
    cnt+=(a[i+idx[k]][j+idy[k]]=='C');
return cnt;
}
void place_p(int i,int j){
    for(int k=0;k<=3;k++)
       if(a[i+idx[k]][j+idy[k]]=='.')a[i+idx[k]][j+idy[k]]='P';
}
void real_ispis(){

   for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
         printf("%c",a[i][j]);
    }
    printf("\n");
   }

}
void ispis(){

   for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
        if(a[i][j]=='P')printf(".");
        else printf("%c",a[i][j]);
    }
    printf("\n");
   }

}
bool can_c(int x,int y){
   if(a[x][y]!='.')return 0;

   int i=x;
   while(1){
      if(a[++i][y]=='C')return 0;
      if(a[i][y]=='#' || cifra(a[i][y]))break;
   }

   i=x;
   while(1){
      if(a[--i][y]=='C')return 0;
      if(a[i][y]=='#' || cifra(a[i][y]))break;
   }

   i=y;
   while(1){
      if(a[x][++i]=='C')return 0;
      if(a[x][i]=='#' || cifra(a[x][i]))break;
   }

   i=y;
   while(1){
      if(a[x][--i]=='C')return 0;
      if(a[x][i]=='#' || cifra(a[x][i]))break;
   }
return 1;
}
void check(){

   if(glcnt==tacka_cnt){
    rez=1;
    ispis();
   }

}
void prep(){

   memset(pos,0,sizeof(pos));
   glcnt=0;

   for(int x=1;x<=n;x++){
     for(int y=1;y<=m;y++){
       if(a[x][y]!='C')continue;

       glcnt++;

       int i=x;
       while(1){
          i++;
          if(a[i][y]=='#' || cifra(a[i][y]))break;
          if(pos[i][y])continue;
          pos[i][y]=1;
          glcnt++;
       }

       i=x;
       while(1){
          i--;
          if(a[i][y]=='#' || cifra(a[i][y]))break;
          if(pos[i][y])continue;
          pos[i][y]=1;
          glcnt++;
       }

       i=y;
       while(1){
          i++;
          if(a[x][i]=='#' || cifra(a[x][i]))break;
          if(pos[x][i])continue;
          pos[x][i]=1;
          glcnt++;
       }

       i=y;
       while(1){
          i--;
          if(a[x][i]=='#' || cifra(a[x][i]))break;
          if(pos[x][i])continue;
          pos[x][i]=1;
          glcnt++;
       }

     }
   }

}
void go2(int x,int y){

   if(y>m){
    x++;
    y=1;
   }
   if(x>n){
     check();
     return;
   }

//   printf("%d %d  GO2\n",x,y);
//   real_ispis();
//   printf("\n");

   if(can_c(x,y)){

     a[x][y]='C';

     pair<int,int>rev[25];
     int revbr=0;

     glcnt++;
     pos[x][y]=1;

     int i=x;
       while(1){
          i++;
          if(a[i][y]=='#' || cifra(a[i][y]))break;
          if(pos[i][y])continue;
          pos[i][y]=1;
          glcnt++;
          rev[++revbr]={i,y};
       }

       i=x;
       while(1){
          i--;
          if(a[i][y]=='#' || cifra(a[i][y]))break;
          if(pos[i][y])continue;
          pos[i][y]=1;
          glcnt++;
          rev[++revbr]={i,y};
       }

       i=y;
       while(1){
          i++;
          if(a[x][i]=='#' || cifra(a[x][i]))break;
          if(pos[x][i])continue;
          pos[x][i]=1;
          glcnt++;
          rev[++revbr]={x,i};
       }

       i=y;
       while(1){
          i--;
          if(a[x][i]=='#' || cifra(a[x][i]))break;
          if(pos[x][i])continue;
          pos[x][i]=1;
          glcnt++;
          rev[++revbr]={x,i};
       }

     go2(x,y+1);

     a[x][y]='.';
     glcnt--;
     pos[x][y]=0;

     for(int i=1;i<=revbr;i++){
        pos[rev[i].first][rev[i].second]=0;
        glcnt--;
     }

     if(rez==1)return;

     go2(x,y+1);

     if(rez==1)return;
   }
   else if(a[x][y]=='#' || cifra(a[x][y])){

     for(int i=x;i>=1;i--)
        if((a[i][y]=='P' || a[i][y]=='.')&&(pos[i][y]==0))return;

     go2(x,y+1);
   }
   else go2(x,y+1);

}
void go(int x,int y){
   if(y>m){
    x++;
    y=1;
   }
   if(x>n){
     prep();
     go2(1,1);
     return;
   }

   ///printf("%d %d\n",x,y);

   if(a[x][y]=='#' || a[x][y]=='C' || a[x][y]=='.' || a[x][y]=='P'){
     go(x,y+1);
     return;
   }

   int cnt=a[x][y]-48;
   cnt-=c_count(x,y);

   if(cnt<0)return;

   int arr[5],br=0,rev[5],revbr=0;

   for(int i=0;i<=3;i++)
      if(can_c(x+idx[i],y+idy[i]))arr[++br]=i;


   if(br<cnt)return;

   for(int i=0;i<(1<<br);i++){
      if(__builtin_popcount(i)!=cnt)continue;

      for(int j=0;j<br;j++){
        if(((1<<j)&i)==0)continue;

        int xx=x+idx[arr[j+1]];
        int yy=y+idy[arr[j+1]];
        a[xx][yy]='C';
      }

      for(int k=0;k<=3;k++)
       if(a[x+idx[k]][y+idy[k]]=='.'){
         a[x+idx[k]][y+idy[k]]='P';
         rev[++revbr]=k;
       }

       go(x,y+1);
       if(rez==1)return;


       for(int j=0;j<br;j++){
        if(((1<<j)&i)==0)continue;

        int xx=x+idx[arr[j+1]];
        int yy=y+idy[arr[j+1]];
        a[xx][yy]='.';
      }

       for(int j=1;j<=revbr;j++){
        int xx=x+idx[rev[j]];
        int yy=y+idy[rev[j]];
        a[xx][yy]='.';
       }
       revbr=0;

   }

}
int main(){

    ///freopen("test.txt","r",stdin);

    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++){
        cin>>s;
        for(int j=1;j<=m;j++){
            a[i][j]=s[j-1];
            if(a[i][j]=='.')tacka_cnt++;
        }
    }

    for(int i=0;i<=n+1;i++){
        a[i][0]='#';
        a[i][m+1]='#';
    }
    for(int i=0;i<=m+1;i++){
        a[0][i]='#';
        a[n+1][i]='#';
    }

    go(1,1);

    if(rez==0)printf("-1\n");

return 0;
}