#include<bits/stdc++.h>
using namespace std;
char s[51][51];
int b,i,j,m,n;
int main()
{
	cin>>n>>m;
	for(i=1;i<=n;++i)
	for(j=1;j<=m;++j)cin>>s[i][j];
	for(i=1;i<=n;++i)
	{
		for(j=1;j<=m;++j)
		{
			if(s[i][j]=='.')
			{
				if(s[i-1][j-1]=='#')b++;
				if(s[i-1][j]=='#')b++;
				if(s[i-1][j+1]=='#')b++;
				if(s[i][j-1]=='#')b++;
				if(s[i][j+1]=='#')b++;
				if(s[i+1][j-1]=='#')b++;
				if(s[i+1][j]=='#')b++;
				if(s[i+1][j+1]=='#')b++;
				cout<<b;
			}
			else cout<<s[i][j];
			b=0;
		}
		cout<<endl;
	}
	
}