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