#include<cstdio>
const int MAXN=50+5;
char map[MAXN][MAXN];int n,m;
int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%s",map[i]+1);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
			if(map[i][j]=='#') printf("%c",'#'); else printf("%d",(map[i-1][j  ]=='#')+(map[i+1][j  ]=='#')+(map[i  ][j-1]=='#')+(map[i  ][j+1]=='#')+(map[i-1][j-1]=='#')+(map[i-1][j+1]=='#')+(map[i+1][j-1]=='#')+(map[i+1][j+1]=='#'));
		printf("\n");
	}
	return 0;
}