#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>

using namespace std;
int h,w,k[55][55];
char c[55][55];
int main()
{
	cin>>h>>w;
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			cin>>c[i][j];
			if(c[i][j]=='#')k[i][j]=1;
		}
	}
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			if(c[i][j]=='#')cout<<"#";
			else
			{
				cout<<k[i-1][j-1]+k[i-1][j]+k[i-1][j+1]+k[i][j-1]+k[i][j+1]+k[i+1][j-1]+k[i+1][j]+k[i+1][j+1];
			}
		}
		cout<<"\n";
	}
	
	return 0;
}