#include <bits/stdc++.h>

using namespace std;

#define INFI 987654321
#define INFL 987654321987654321
#define MOD 1000000007

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<typename T>
void read(T, int);

template<typename T>
void write(T, int);

template<typename T>
int sumFor(T, int, int);

template<typename T>
int sumFor(T, int);

int power(int, int, int);
int power(int, int);
void add(int&, int&);
int getRand();
int max(int, int, int);

/// //MAIN// ///

//int a[500005];

char mat[15][15];
char tmat[15][15];
vector<pair<int, int>> kock;
bool foundIt = false;

int n, m;

int btopova(int x, int y){

    int bt = 0;
    if(x != n - 1 && tmat[x+1][y] == 'C'){
        bt++;
    }
    if(x != 0 && tmat[x-1][y] == 'C'){
        bt++;
    }
    if(y != m - 1 && tmat[x][y+1] == 'C'){
        bt++;
    }
    if(y != 0 && tmat[x][y-1] == 'C'){
        bt++;
    }

    return bt;
}

bool goUp(int x, int y){

        if(x - 1 >= 0 && tmat[x-1][y] == '.'){
            tmat[x-1][y] = 'C';
            return true;
        }
        return false;
}

void cancelUp(int x, int y){

    tmat[x-1][y] = '.';
}

bool goDown(int x, int y){
            if(x + 1 < n && tmat[x+1][y] == '.'){
                tmat[x+1][y] = 'C';
                return true;
            }
            return false;
}

void cancelDown(int x, int y){
            tmat[x+1][y] = '.';
}

bool goLeft(int x, int y){
        if(y - 1 >= 0 && tmat[x][y-1] == '.'){
            tmat[x][y-1] = 'C';
            return true;
        }
        return false;
}

void cancelLeft(int x, int y){
                tmat[x][y-1] = '.';
}

bool goRight(int x, int y){
            if(y + 1 < m && tmat[x][y+1] == '.' ){
                tmat[x][y+1] = 'C';
                return true;
            }
            return false;
}

void cancelRight(int x, int y){

            tmat[x][y+1] = '.';
}

void rek(int);

void addOne(int x, int y, int sq){
        if(goUp(x, y)){
            rek(sq + 1);
            cancelUp(x, y);
        }

        if(goDown(x, y)){
            rek(sq + 1);
            cancelDown(x, y);
        }

        if(goLeft(x, y)){
            rek(sq + 1);
            cancelLeft(x, y);
        }

        if(goRight(x, y)){
            rek(sq + 1);
            cancelRight(x, y);
        }
}

void addTwo(int x, int y, int sq){
            if(goUp(x, y)){
                if(goLeft(x, y)){
                    rek(sq + 1);
                    cancelLeft(x, y);
                }
                if(goRight(x, y)){
                    rek(sq + 1);
                    cancelRight(x, y);
                }
                if(goDown(x, y)){
                    rek(sq + 1);
                    cancelDown(x, y);
                }
                cancelUp(x, y);
            }
            if(goDown(x, y)){
                if(goLeft(x, y)){
                    rek(sq + 1);
                    cancelLeft(x, y);
                }
                if(goRight(x, y)){
                    rek(sq + 1);
                    cancelRight(x, y);
                }
                cancelDown(x, y);
            }
            if(goRight(x, y)){
                if(goLeft(x, y)){
                    rek(sq + 1);
                    cancelLeft(x, y);
                }
                cancelRight(x, y);
            }
}

void addThree(int x, int y, int sq){

    if(goUp(x, y)){
        if(goDown(x, y)){
            if(goLeft(x, y)){
                rek(sq + 1);
                cancelLeft(x, y);
            }
            if(goRight(x, y)){
                rek(sq + 1);
                cancelRight(x, y);
            }
            cancelDown(x, y);
        }
        if(goLeft(x, y)){
            if(goRight(x, y)){
                rek(sq + 1);
                cancelRight(x, y);
            }
            cancelLeft(x, y);
        }
        cancelUp(x, y);
    }

    if(goDown(x, y)){
        if(goLeft(x, y)){
            if(goRight(x, y)){
                rek(sq + 1);
                cancelRight(x, y);
            }
            cancelLeft(x, y);
        }
        cancelDown(x, y);
    }
}

void addFour(int x, int y, int sq){
    if(goUp(x, y)){
        if(goDown(x, y)){
            if(goLeft(x, y)){
                if(goRight(x, y)){
                    rek(sq + 1);
                    cancelRight(x, y);
                }
                cancelLeft(x, y);
            }
            cancelDown(x, y);
        }
        cancelUp(x, y);
    }
}

bool proveriCol(int x, int y){

    bool fnd = false;
    for(int i = x + 1; i < n; ++i){
        if(mat[i][y] == '#' || (mat[i][y] >= '0' && mat[i][y] <= '4')){
            break;
        }
        if(tmat[i][y] == 'C'){
            fnd = true;
            break;
        }
    }

    if(fnd){
        return true;
    }

    for(int i = x - 1; i >= 0; --i){
        if(mat[i][y] == '#'  || (mat[i][y] >= '0' && mat[i][y] <= '4')){
            break;
        }
        if(tmat[i][y] == 'C'){
            fnd = true;
            break;
        }
    }

    if(fnd){
        return true;
    }

    for(int i = y + 1; i < m; ++i){
        if(mat[x][i] == '#' || (mat[x][i] >= '0' && mat[x][i] <= '4')){
            break;
        }
        if(tmat[x][i] == 'C'){
            fnd = true;
            break;
        }
    }

    if(fnd){
        return true;
    }

    for(int i = y - 1; i >= 0; --i){
        if(mat[x][i] == '#' || (mat[x][i] >= '0' && mat[x][i] <= '4')){
            break;
        }
        if(tmat[x][i] == 'C'){
            fnd = true;
            break;
        }
    }

    if(fnd){
        return true;
    }

    return false;
}

void rek(int sq){

    if(sq == (int)kock.size()){

        bool works = true;
        for(pair<int, int> z : kock){
            if(mat[z.first][z.second] - '0' != btopova(z.first, z.second)){
                works = false;
                break;
            }
        }

        if(!works){
            return;
        }

        for(int i = 0; i < n; ++i){
            for(int j = 0; j < m; ++j){
                if(tmat[i][j] == 'C'){
                    if(proveriCol(i, j)){
                        works = false;
                        break;
                    }
                }
            }
        }

        if(works){
            for(int i = 0; i < n; ++i){
                for(int j = 0; j < m; ++j){
                    cout << tmat[i][j];
                }
                cout << "\n";
            }
            exit(0);
        }else{
            return;
        }

        return;
    }

    int x = kock[sq].first, y = kock[sq].second;
    int val = mat[x][y] - '0';
    int bt = btopova(x, y);


    if(val == 0){
        if(bt > 0){
            return;
        }
        rek(sq + 1);
        return;
    }else if(val == 1){
        if(bt > 1){
            return;
        }
        if(bt == 1){
            rek(sq + 1);
            return;
        }

        addOne(x, y, sq);
        return;

    }else if(val == 2){
        if(bt > 2){
            return;
        }
        if(bt == 2){
            rek(sq + 1);
            return;
        }

        if(bt == 0){
            addTwo(x, y, sq);
            return;
        }else{
            addOne(x, y, sq);
            return;
        }

    }else if(val == 3){
        if(bt > 3){
            return;
        }
        if(bt == 3){
            rek(sq + 1);
            return;
        }

        if(bt == 2){
            addOne(x, y, sq);
            return;
        }else if(bt == 1){
            addTwo(x, y, sq);
            return;
        }else{
            addThree(x, y, sq);
        }

    }else{ //x == 4
        if(bt == 4){
            rek(sq + 1);
            return;
        }
        if(bt == 3){
            addOne(x, y, sq);
        }else if(bt == 2){
            addTwo(x, y, sq);
        }else if(bt == 1){
            addThree(x, y, sq);
        }else{
            addFour(x, y, sq);
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> m;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < m; ++j){
            cin >> mat[i][j];
            if(mat[i][j] >= '0' && mat[i][j] <= '4'){
                kock.push_back({i, j});
            }
            tmat[i][j] = mat[i][j];
        }
    }

    rek(0);
    cout << "-1\n";
    return 0;
}

/// /////////////////////////////////////////////

int max(int m_a, int m_b, int m_c){
    if(m_c >= m_a && m_c >= m_b){
        return m_c;
    }
    return m_a >= m_b ? m_a : m_b;
}

int getRand(){
    return rng();
}

void add(int& m_a, int& m_b){
    m_a = (m_a + m_b) % MOD;
}

template<typename T>
void write(T m_pnter, int m_size){
    for(int i = 0; i < m_size; ++i){
        cout << m_pnter[i] << " ";
    }
    cout << "\n";
}

template<typename T>
void read(T m_pnter, int m_size){
    for(int i = 0; i < m_size; ++i){
        cin >> m_pnter[i];
    }
}

template<typename T>
int sumFor(T m_pnter, int m_l, int m_r){
    int m_sum = 0;
    for(int i = m_l; i < m_r; ++i){
        m_sum += m_pnter[i];
    }
    return m_sum;
}

template<typename T>
int sumFor(T m_pnter, int m_r){
    int m_sum = 0;
    for(int i = 0; i < m_r; ++i){
        m_sum += m_pnter[i];
    }
    return m_sum;
}

int power(int m_a, int m_b, int m_mod){
    int m_res = 1;
    while(m_b > 0){
        if(m_b % 2 == 1){
            m_res = (m_res * m_a) % m_mod;
        }
        m_b /= 2;
        m_a = (m_a * m_a) % m_mod;
    }
    return m_res;
}

int power(int m_a, int m_b){
    int m_res = 1;
    while(m_b > 0){
        if(m_b % 2 == 1){
            m_res = m_res * m_a;
        }
        m_b /= 2;
        m_a = m_a * m_a;
    }
    return m_res;
}