#include<iostream>
using namespace std;
char a[105][105];
int main()
{
	int n,m,i,j,s=0;
	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++)
		{
		s=0;
			if(a[i][j]=='#')cout<<"#";
			else if(a[i][j]=='.')
			{
				if(a[i-1][j-1]=='#')s++;
				if(a[i-1][j]=='#')s++;
				if(a[i-1][j+1]=='#')s++;
				if(a[i][j-1]=='#')s++;
				if(a[i][j+1]=='#')s++;
				if(a[i+1][j-1]=='#')s++;
				if(a[i+1][j]=='#')s++;
				if(a[i+1][j+1]=='#')s++;
				cout<<s;
			}
		}
		cout<<endl;
	}
	
}
