#include <stdio.h>
#include <string.h>
char a[1000][1000];
int l, c;
int much(int x, int y) {
int cnt = 0;
if (x + 1 <= c) {
if (a[x + 1][y] == '*') cnt++;
}
if (x - 1 >= 0) {
if (a[x - 1][y] == '*') cnt++;
}
if (y - 1 >= 0) {
if (a[x][y - 1] == '*') cnt++;
}
if (y + 1 <= l) {
if (a[x][y + 1] == '*') cnt++;
}
if (x + 1 <= c && y + 1 <= l) {
if (a[x + 1][y + 1] == '*') cnt++;
}
if (x - 1 >= 0 && y - 1 >= 0) {
if (a[x - 1][y - 1] == '*') cnt++;
}
if (x + 1 <= c && y - 1 >= 0) {
if (a[x + 1][y - 1] == '*') cnt++;
}
if (x - 1 >= 0 && y + 1 <= l) {
if (a[x - 1][y + 1] == '*') cnt++;
}
return cnt;
}
int main () {
scanf("%d%d", &l, &c);
for (int i = 0; i < l; i++) {
scanf("%s", a[i]);
}
for (int i = 0; i < l; i++) {
for (int j = 0; j < c; j++) {
if (a[i][j] != '*') {
a[i][j] = much(i, j)+48;
}
}
}
for (int i = 0; i < l; i++) {
if(i!=l-1) printf("%s\n",a[i]);
else printf("%s",a[i]);
}
}