// asdasdasda as dasd 
#include <bits/stdc++.h>
using namespace std;
#define REP(a,b,c) for(int a=b;a<c;a++)
#define asd(x)              cout<<__LINE__<<" :: "<<#x<< ": "<<x<<endl;
#define asdf(x, y)          cout<<__LINE__<<" :: "<<#x<< ": "<<x<<" | "<<#y<< ": "<<y<<endl;
#define lb() cout << string(15, =) << endl
typedef pair<int,int> ii;
typedef long long LL;
void scan(); void print(); bool rec(int,int,int);
const int M = 10;
int space[M][M], sum[M][M][2], len[M][M][2], avail[M][M][2], G[M][M], dp[41][1<<M][M], setbit[1<<M], n, m;

vector<ii> store;
void brute(int idx){
    if(idx == store.size()) print();
    int x = store[idx].first, y = store[idx].second;
    int mask = avail[x][y][0] & avail[x][y][1];

    if(not rec(sum[x][y][0], avail[x][y][0], len[x][y][0]) || not rec(sum[x][y][1], avail[x][y][1], len[x][y][1]))
        return ;

    while(mask){
        int high = setbit[mask];
        mask -= (1 << high);
        if(min(sum[x][y][0], sum[x][y][1]) - (high + 1) < 0) return;
        if(not rec(sum[x][y][0] - high - 1, avail[x][y][0] - (1 << high), len[x+1][y][0])) continue;
        if(not rec(sum[x][y][1] - high - 1, avail[x][y][1] - (1 << high), len[x][y+1][1])) continue;
        sum[x+1][y][0] = sum[x][y][0] - high - 1;
        sum[x][y+1][1] = sum[x][y][1] - high - 1;
        avail[x+1][y][0] = avail[x][y][0] - (1 << high);
        avail[x][y+1][1] = avail[x][y][1] - (1 << high);
        G[x][y] = high + 1;
        brute(idx + 1);
    }
}

int main(){
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    memset(dp, -1, sizeof dp);
    scan();
    brute(0);
    return 0;
}

bool rec(int sum, int mask, int len){
//    printf("here %d %d %d\n", sum, mask, len);
    int &ret = dp[sum][mask][len];
    if(ret != -1) return ret;
    if(sum == 0 and len == 0) return ret = true;
    if(sum == 0 or len == 0) return ret = false;

    REP(i, 0, 9){
        if(sum - i - 1 < 0) break;
        if(mask & (1 << i)){
            if(rec(sum - i - 1, mask - (1 << i), len - 1)) return ret = true;
        }
    }
    return ret = false;
}

void scan(){
    cin >> n >> m;
    string str;
    REP(i, 0, M) REP(j, 0, M) 
        avail[i][j][0] = avail[i][j][1] = (1 << 9) - 1;
    REP(i, 0, n) REP(j, 0, m){
        cin >> str;
        if(str == ".....") space[i][j] = true, store.push_back(ii(i, j));
        else{
            if(str[0] != 'X') sum[i+1][j][0] = (str[0] - '0')*10 + (str[1] - '0');
            if(str[3] != 'X') sum[i][j+1][1] = (str[3] - '0')*10 + (str[4] - '0');
        }
    }

    for(int i = n - 1; i >= 0; i--) for(int j = m - 1; j >= 0; j--){
        if(space[i][j]){
            len[i][j][0] = 1 + (space[i+1][j] ? len[i+1][j][0] : 0);
            len[i][j][1] = 1 + (space[i][j+1] ? len[i][j+1][1] : 0);
        }
    }


    REP(mask, 0, (1 << 9)) REP(bit, 0, 9) if(mask & (1 << bit)){
        setbit[mask] = bit;
        break;
    }
}

void print(){
    REP(i, 0, n){
        REP(j, 0, m){
            if(space[i][j]) printf("%d", G[i][j]);
            else printf("_");
            printf("%c", (j == m - 1) ? '\n' : ' ');
        }
    }
    exit(0);
}