#include <cstdio>
char M[100][100];
int main()
{
	int h,w;
	scanf("%d%d",&h,&w);
	for (int i = 0; i < h; i++)
		scanf("%s",M[i]);
	for (int i = 0; i < h; i++)
	for (int j = 0; j < w; j++)
	{
		if (M[i][j] != '#')
		{
			int cnt = 0;
			for (int x = -1; x <= 1; x++)
			for (int y = -1; y <= 1; y++)
			{
				if (i + x >= 0 && i + x < h && j + y >= 0 && j + y < w && M[x + i][y + j] == '#')
					cnt++;
			}
			M[i][j] = '0' + cnt;
		}
	}
	for (int i = 0; i < h; i++)
		printf("%s\n",M[i]);
} 