#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std;
using namespace __gnu_cxx;
#define sz(x) (int)x.size()
int n,m;
char arr[1010][1010];
int vis[1010][1010];
int num[1010][1010];
int visId;
int cnt[1010];
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
void dfs(int r,int c){
if(r<0||c<0||r>=n||c>=m)return;
if(vis[r][c]||arr[r][c]=='*')return;
vis[r][c]=1;
num[r][c]=visId;
cnt[visId]++;
for(int i=0;i<4;i++)
dfs(r+dx[i],c+dy[i]);
return;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);
#endif
scanf("%d %d",&n,&m);
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
scanf(" %c",&arr[i][j]);
for(int i=0;i<n;i++)
for(int j=0;j<m;j++){
if(vis[i][j]||arr[i][j]=='*')continue;
visId++;
dfs(i,j);
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(arr[i][j]=='.'){
printf(".");
continue;
}
set<int> st;
if(i>0&&arr[i-1][j]=='.')st.insert(num[i-1][j]);
if(i<n-1&&arr[i+1][j]=='.')st.insert(num[i+1][j]);
if(j>0&&arr[i][j-1]=='.')st.insert(num[i][j-1]);
if(j<m-1&&arr[i][j+1]=='.')st.insert(num[i][j+1]);
int ans=1;
for(set<int>::iterator it=st.begin();it!=st.end();it++)
ans+=cnt[*it];
printf("%d",ans%10);
}
cout<<"\n";
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNpbmNsdWRlIDxleHQvbnVtZXJpYz4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdXNpbmcgbmFtZXNwYWNlIF9fZ251X2N4eDsKCiNkZWZpbmUgc3ooeCkgKGludCl4LnNpemUoKQoKaW50IG4sbTsKY2hhciBhcnJbMTAxMF1bMTAxMF07CmludCB2aXNbMTAxMF1bMTAxMF07CmludCBudW1bMTAxMF1bMTAxMF07CmludCB2aXNJZDsKaW50IGNudFsxMDEwXTsKaW50IGR4WzRdPXsxLC0xLDAsMH07CmludCBkeVs0XT17MCwwLDEsLTF9OwoKdm9pZCBkZnMoaW50IHIsaW50IGMpewogICAgaWYocjwwfHxjPDB8fHI+PW58fGM+PW0pcmV0dXJuOwogICAgaWYodmlzW3JdW2NdfHxhcnJbcl1bY109PScqJylyZXR1cm47CiAgICB2aXNbcl1bY109MTsKICAgIG51bVtyXVtjXT12aXNJZDsKICAgIGNudFt2aXNJZF0rKzsKICAgIGZvcihpbnQgaT0wO2k8NDtpKyspCiAgICAgICAgZGZzKHIrZHhbaV0sYytkeVtpXSk7CiAgICByZXR1cm47Cn0KCmludCBtYWluKCkgewojaWZuZGVmIE9OTElORV9KVURHRQogICAgZnJlb3BlbigiaW5wdXQudHh0IiwgInJ0Iiwgc3RkaW4pOwogICAvLyBmcmVvcGVuKCJvdXRwdXQudHh0IiwgInd0Iiwgc3Rkb3V0KTsKI2VuZGlmCiAgICBzY2FuZigiJWQgJWQiLCZuLCZtKTsKICAgIGZvcihpbnQgaT0wO2k8bjtpKyspCiAgICAgICAgZm9yKGludCBqPTA7ajxtO2orKykKICAgICAgICAgICAgc2NhbmYoIiAlYyIsJmFycltpXVtqXSk7CiAgICBmb3IoaW50IGk9MDtpPG47aSsrKQogICAgICAgIGZvcihpbnQgaj0wO2o8bTtqKyspewogICAgICAgICAgICBpZih2aXNbaV1bal18fGFycltpXVtqXT09JyonKWNvbnRpbnVlOwogICAgICAgICAgICB2aXNJZCsrOwogICAgICAgICAgICBkZnMoaSxqKTsKICAgICAgICB9CgogICAgZm9yKGludCBpPTA7aTxuO2krKyl7CiAgICAgICAgZm9yKGludCBqPTA7ajxtO2orKyl7CiAgICAgICAgICAgIGlmKGFycltpXVtqXT09Jy4nKXsKICAgICAgICAgICAgICAgIHByaW50ZigiLiIpOwogICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgc2V0PGludD4gc3Q7CiAgICAgICAgICAgIGlmKGk+MCYmYXJyW2ktMV1bal09PScuJylzdC5pbnNlcnQobnVtW2ktMV1bal0pOwogICAgICAgICAgICBpZihpPG4tMSYmYXJyW2krMV1bal09PScuJylzdC5pbnNlcnQobnVtW2krMV1bal0pOwogICAgICAgICAgICBpZihqPjAmJmFycltpXVtqLTFdPT0nLicpc3QuaW5zZXJ0KG51bVtpXVtqLTFdKTsKICAgICAgICAgICAgaWYoajxtLTEmJmFycltpXVtqKzFdPT0nLicpc3QuaW5zZXJ0KG51bVtpXVtqKzFdKTsKICAgICAgICAgICAgaW50IGFucz0xOwogICAgICAgICAgICBmb3Ioc2V0PGludD46Oml0ZXJhdG9yIGl0PXN0LmJlZ2luKCk7aXQhPXN0LmVuZCgpO2l0KyspCiAgICAgICAgICAgICAgICBhbnMrPWNudFsqaXRdOwogICAgICAgICAgICBwcmludGYoIiVkIixhbnMlMTApOwogICAgICAgIH0KICAgICAgICBjb3V0PDwiXG4iOwogICAgfQp9