#include <bits/stdc++.h>
using namespace std;
char x[1001][1001];
int main()
{
	int a,b;
	cin>>a>>b;
	for(int i=1;i<=a;i++)
		for(int j=1;j<=b;j++)
			cin>>x[i][j];
	for(int i=1;i<=a;i++)
	{
		for(int j=1;j<=b;j++)
		{
			int cnt=0;
			if(x[i+1][j+1]=='#')cnt++;
			if(x[i+1][j-1]=='#')cnt++;
			if(x[i+1][j]=='#')cnt++;
			if(x[i][j+1]=='#')cnt++;
			if(x[i][j-1]=='#')cnt++;
			if(x[i-1][j+1]=='#')cnt++;
			if(x[i-1][j]=='#')cnt++;
			if(x[i-1][j-1]=='#')cnt++;
			if(x[i][j]=='#'){cout<<'#';continue;}
			cout<<cnt;
			cnt=0;
		}
		cout<<'\n';
	}
	return 0;
}
