#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	char c[a+2][b+2];
	int sum[a+2][b+2];
	memset(sum,0,sizeof(sum));
	for(int i=1;i<=a;i++) 
		for(int j=1;j<=b;j++)
		{
			cin>>c[i][j];
			if(c[i][j]=='#')
			{
				sum[i-1][j-1]++;
				sum[i-1][j]++;
				sum[i-1][j+1]++;
				sum[i][j-1]++;
				sum[i][j+1]++;
				sum[i+1][j-1]++;
				sum[i+1][j]++;
				sum[i+1][j+1]++;
			}
		}
	for(int i=1;i<=a;i++)
	{
		for(int j=1;j<=b;j++)
			if(c[i][j]=='.')
				cout<<sum[i][j];
			else
				cout<<c[i][j];
		cout<<endl;
	}
	return 0;
 } 