#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main() {
int m, n;
scanf("%d %d", &m, &n);
char **matrix = malloc(sizeof(char*)*m);
for (int i = 0; i < m; i++) {
matrix[i] = malloc(sizeof(char)*(n + 1));
memset(matrix[i], 0, sizeof(char)*(n + 1));
}
for (int i = 0; i < m; i++) {
scanf("%s", matrix[i]);
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (matrix[i][j] == '*') {
continue;
matrix[i][j] = '0';
}
}
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (matrix[i][j] == '*') {
for (int y = i - 1; y <= i + 1; y++) {
for (int x = j - 1; x <= j + 1; x++) {
if (y < 0 || x < 0 || y >= m || x >= n) {
continue;
matrix[y][x] += 1;
}
}
}
}
}
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (matrix[i][j] == '*') {
printf("*");
}
else
printf("%d", matrix[i][j]);
}
printf("\n");
}
for (int i = 0; i < m; i++) {
free(matrix[i]);
}
free(matrix);
return 0;
}