#include<bits/stdc++.h>
using namespace std;
int n,m,i,j;bool b[52][52];char c;
int main(){
	cin>>n>>m;
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++){
			cin>>c;
			if(c=='#')
				b[i][j]=1;
		}
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++)
			b[i][j]==1?printf("#"):printf("%d",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]);
		printf("\n");
	}
	return 0;
}