// 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);
}
Ly8gYXNkYXNkYXNkYSBhcyBkYXNkIAojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBSRVAoYSxiLGMpIGZvcihpbnQgYT1iO2E8YzthKyspCiNkZWZpbmUgYXNkKHgpICAgICAgICAgICAgICBjb3V0PDxfX0xJTkVfXzw8IiA6OiAiPDwjeDw8ICI6ICI8PHg8PGVuZGw7CiNkZWZpbmUgYXNkZih4LCB5KSAgICAgICAgICBjb3V0PDxfX0xJTkVfXzw8IiA6OiAiPDwjeDw8ICI6ICI8PHg8PCIgfCAiPDwjeTw8ICI6ICI8PHk8PGVuZGw7CiNkZWZpbmUgbGIoKSBjb3V0IDw8IHN0cmluZygxNSwgPSkgPDwgZW5kbAp0eXBlZGVmIHBhaXI8aW50LGludD4gaWk7CnR5cGVkZWYgbG9uZyBsb25nIExMOwp2b2lkIHNjYW4oKTsgdm9pZCBwcmludCgpOyBib29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ICAgIH0KICAgIHJldHVybiByZXQgPSBmYWxzZTsKfQoKdm9pZCBzY2FuKCl7CiAgICBjaW4gPj4gbiA+PiBtOwogICAgc3RyaW5nIHN0cjsKICAgIFJFUChpLCAwLCBNKSBSRVAoaiwgMCwgTSkgCiAgICAgICAgYXZhaWxbaV1bal1bMF0gPSBhdmFpbFtpXVtqXVsxXSA9ICgxIDw8IDkpIC0gMTsKICAgIFJFUChpLCAwLCBuKSBSRVAoaiwgMCwgbSl7CiAgICAgICAgY2luID4+IHN0cjsKICAgICAgICBpZihzdHIgPT0gIi4uLi4uIikgc3BhY2VbaV1bal0gPSB0cnVlLCBzdG9yZS5wdXNoX2JhY2soaWkoaSwgaikpOwogICAgICAgIGVsc2V7CiAgICAgICAgICAgIGlmKHN0clswXSAhPSAnWCcpIHN1bVtpKzFdW2pdWzBdID0gKHN0clswXSAtICcwJykqMTAgKyAoc3RyWzFdIC0gJzAnKTsKICAgICAgICAgICAgaWYoc3RyWzNdICE9ICdYJykgc3VtW2ldW2orMV1bMV0gPSAoc3RyWzNdIC0gJzAnKSoxMCArIChzdHJbNF0gLSAnMCcpOwogICAgICAgIH0KICAgIH0KCiAgICBmb3IoaW50IGkgPSBuIC0gMTsgaSA+PSAwOyBpLS0pIGZvcihpbnQgaiA9IG0gLSAxOyBqID49IDA7IGotLSl7CiAgICAgICAgaWYoc3BhY2VbaV1bal0pewogICAgICAgICAgICBsZW5baV1bal1bMF0gPSAxICsgKHNwYWNlW2krMV1bal0gPyBsZW5baSsxXVtqXVswXSA6IDApOwogICAgICAgICAgICBsZW5baV1bal1bMV0gPSAxICsgKHNwYWNlW2ldW2orMV0gPyBsZW5baV1baisxXVsxXSA6IDApOwogICAgICAgIH0KICAgIH0KCgogICAgUkVQKG1hc2ssIDAsICgxIDw8IDkpKSBSRVAoYml0LCAwLCA5KSBpZihtYXNrICYgKDEgPDwgYml0KSl7CiAgICAgICAgc2V0Yml0W21hc2tdID0gYml0OwogICAgICAgIGJyZWFrOwogICAgfQp9Cgp2b2lkIHByaW50KCl7CiAgICBSRVAoaSwgMCwgbil7CiAgICAgICAgUkVQKGosIDAsIG0pewogICAgICAgICAgICBpZihzcGFjZVtpXVtqXSkgcHJpbnRmKCIlZCIsIEdbaV1bal0pOwogICAgICAgICAgICBlbHNlIHByaW50ZigiXyIpOwogICAgICAgICAgICBwcmludGYoIiVjIiwgKGogPT0gbSAtIDEpID8gJ1xuJyA6ICcgJyk7CiAgICAgICAgfQogICAgfQogICAgZXhpdCgwKTsKfQ==