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