#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int f[60][60],i,k,m,n;
char a[60][60];
inline void w(int i,int k)
{
	f[i][k+1]++;
	f[i][k-1]++;
	f[i+1][k]++;
	f[i-1][k]++;
	f[i+1][k+1]++;
	f[i-1][k-1]++;
	f[i+1][k-1]++;
	f[i-1][k+1]++;
}
int main()
{
	cin>>m>>n;
	for(i=1;i<=m;i++)
	{
		for(k=1;k<=n;k++)
		{
			cin>>a[i][k];
			if(a[i][k]=='#')
			w(i,k);
		}
	}
	for(i=1;i<=m;i++)
	{
		for(k=1;k<=n;k++)
		{
			if(a[i][k]=='#')
			printf("#");
			else
			printf("%d",f[i][k]);
		}
		printf("\n");
	}
	return 0;
}