#include <iostream>
using namespace std;
char a[101][101]={};
int i,j,k,n,m;
int main()
{
	cin>>n>>m;
	for(i=1;i<=n;i++)
	for(j=1;j<=m;j++)
	cin>>a[i][j];
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			if(a[i][j]=='#') cout<<"#";
			else{
				k=0;
				if(a[i+1][j+1]=='#') k++;
				if(a[i][j+1]=='#') k++;
				if(a[i-1][j+1]=='#') k++;
				if(a[i+1][j]=='#') k++;
				if(a[i-1][j]=='#') k++;
				if(a[i+1][j-1]=='#') k++;
				if(a[i][j-1]=='#') k++;
				if(a[i-1][j-1]=='#') k++;
				cout<<k;
			}
		}
		cout<<endl;
	}
	return 0;
}