#include <iostream>
using namespace std;
int main()
{
	int h=0,v=0,d=0;int n,m;
	cin>>n>>m;char a[n][m];
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			cin>>a[i][j];
		}
	}
	
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			if(a[i][j]=='.')
			{
				for(int k=i-1;k<=i+1;k++)
				{
					for (int l = j-1; l<=j+1 ; l++)
					{
						if(l>=0 && k>=0 && l<m && k<n)
						{
							if(a[k][l]=='#' )
								h++;
						}
					}
				}
				cout<<h;
				
			}
			else
				{cout<<a[i][j];}

			h=0;
		}
		cout<<endl;
		
	}
	

}