#include <iostream>
using namespace std;
int n,m,f[61][61];
bool map[61][61];
char x;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	{
		cin>>x;
		if(x=='#') map[i][j]=1;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(!map[i][j])
			cout<<map[i-1][j-1]+map[i-1][j]+map[i-1][j+1]+map[i][j-1]+map[i][j+1]+map[i+1][j-1]+map[i+1][j]+map[i+1][j+1];
			else
			cout<<'#';
		}
		cout<<endl;
	}
	return 0;
}