#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
const int M = 1010;
const int N = 1e6 + 10;
int n, m, p[N], size_[N];
char g[M][M];
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
int find(int x){
if (p[x] != x)
p[x] = find(p[x]);
return p[x];
}
int get(int x, int y){
return (x - 1) * m + y;
}
int main(){
scanf("%d%d", &n, &m);
for (int i = 1; i <= n * m; i++)
p[i] = i, size_[i] = 1;
char ch;
scanf("%c", &ch);
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
scanf("%c", &g[i][j]);
}
scanf("%c", &ch);
}
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
if (g[i][j] == '*')
continue;
int id1 = get(i, j);
for (int k = 0; k < 4; k++){
int x = i + dx[k], y = j + dy[k];
if (x >= 1 && x <= n && y >= 1 && y <= m && g[x][y] == '.'){
int id2 = get(x, y);
if (find(id1) != find(id2)){
size_[find(id2)] += size_[find(id1)];
p[find(id1)] = find(id2);
}
}
}
}
}
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
if (g[i][j] == '.'){
printf("%c", g[i][j]);
continue;
}
int ans = 1;
set<int> nodes;
for (int k = 0; k < 4; k++){
int x = i + dx[k], y = j + dy[k];
if (x >= 1 && x <= n && y >= 1 && y <= m && g[x][y] == '.'){
int id = get(x, y);
int father = find(id);
if (! nodes.count(father)){
nodes.insert(father);
ans += size_[father];
}
}
}
printf("%d", ans % 10);
}
printf("\n");
}
}