#include <bits/stdc++.h>

#define ll long long
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000009

using namespace std;

int n,m;
char c[13][13];
int cnt=0;

bool pokusaj(int p,int q){
    for (int i=p;i>=1;i--){
        if (c[i][q]=='#' or (c[i][q]>='0' and c[i][q]<='4'))break;
        if (c[i][q]=='C')return true;
    }
    for (int i=p;i<=n;i++){
        if (c[i][q]=='#' or (c[i][q]>='0' and c[i][q]<='4'))break;
        if (c[i][q]=='C')return true;
    }
    for (int j=q;j>=1;j--){
        if (c[p][j]=='#' or (c[p][j]>='0' and c[p][j]<='4'))break;
        if (c[p][j]=='C')return true;
    }
    for (int j=q;j<=m;j++){
        if (c[p][j]=='#' or (c[p][j]>='0' and c[p][j]<='4'))break;
        if (c[p][j]=='C')return true;
    }
    return false;
}
void print(){
    for (int i=1;i<=n;i++){
        for (int j=1;j<=m;j++){
            cout<<c[i][j];
        }cout<<"\n";
    }cout<<"\n";
}

bool broj(char s){
    int x=s-'0';
    if (x>=0 and x<=4)return true;
    else return false;
}

void probaj(){
    for (int i=1;i<=n;i++){
        for (int j=1;j<=m;j++){
            if (c[i][j]=='.' and !pokusaj(i,j) and
                !broj(c[i-1][j]) and !broj(c[i+1][j]) and !broj(c[i][j+1]) and !broj(c[i][j-1]) ){
                c[i][j]='C';
                probaj();
                c[i][j]='.';
            }
        }
    }
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
            if (c[i][j]=='.' and !pokusaj(i,j)){
                return;
            }
    print();
    exit(0);
}

void solve(){
    for (int i=1;i<=n;i++){
        for (int j=1;j<=m;j++){
            if (c[i][j]=='.' or c[i][j]=='#' or c[i][j]=='C')continue;

            int cnt=0,num=c[i][j]-'0';
            if (c[i-1][j]=='C')cnt++;
            if (c[i+1][j]=='C')cnt++;
            if (c[i][j-1]=='C')cnt++;
            if (c[i][j+1]=='C')cnt++;

            if (cnt>num)return;
            if (cnt==num)continue;

            if (c[i-1][j]=='.' and !pokusaj(i-1,j)){
                c[i-1][j]='C';
                solve();
                c[i-1][j]='.';
            }

            if (c[i+1][j]=='.' and !pokusaj(i+1,j)){
                c[i+1][j]='C';
                solve();
                c[i+1][j]='.';
            }

            if (c[i][j+1]=='.' and !pokusaj(i,j+1)){
                c[i][j+1]='C';
                solve();
                c[i][j]='.';
            }
            if (c[i][j-1]=='.' and !pokusaj(i,j-1)){
                c[i][j-1]='C';
                solve();
                c[i][j-1]='.';
            }
            return;
        }
    }
    probaj();
}

void input(){
    cin>>n>>m;
    for (int i=1;i<=n;i++){
        for (int j=1;j<=m;j++){
            cin>>c[i][j];
            c[0][j]='#';
            c[n+1][j]='#';
        }
        c[i][0]='#',c[i][m+1]='#';
    }
}
void random(){
    srand (time(NULL));
    n=10,m=10;
    for (int i=1;i<=n;i++){
        for (int j=1;j<=m;j++){
            int x=rand()%100;
            if (x>=3)c[i][j]='.';
            else c[i][j]='1';
            cout<<c[i][j]<<" ";
        }
        cout<<"\n";
    }
}

int main(){
    ios;
    //random();
    input();
    cout<<"\n";
    solve();
    cout<<-1;
    return 0;
}