#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, 0, sizeof(char));
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;
else
{
matrix[i][j] = 0;
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;
else if (matrix[y][x] == '*')
matrix[i][j] += 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;
}