#include <stdio.h>
int main()
{
	int count = 0;
	int n, m;
	scanf("%d%d", &n, &m);
	//吃掉回车
	getchar();
	char arr[1000][1000];
	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 (arr[i][j] == '.')
			{
				//判断四面八方
				count = 0;
				if (arr[i][j - 1] == '*')count++;
				if (arr[i][j + 1] == '*')count++;
				if (arr[i - 1][j] == '*')count++;
				if (arr[i - 1][j - 1] == '*')count++;
				if (arr[i - 1][j + 1] == '*')count++;
				if (arr[i + 1][j] == '*')count++;
				if (arr[i + 1][j - 1] == '*')count++;
				if (arr[i + 1][j + 1] == '*')count++;
				//算出的是int类型 让count 加 48 = 字符类型的数字
				arr[i][j] = count + 48;
			}
			else
			{
				arr[i][j] = '*';
			}
		}
	}
	//输出
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			printf("%c", arr[i][j]);
		}
		printf("\n");
	}
	return 0;
}