#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m;
char s[55];
int ans[55][55],b[55][55];
int mvx[9]={0,1,-1,0,0,1,-1,1,-1},mvy[9]={0,0,0,1,-1,1,-1,-1,1};
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i) {
		scanf("%s",s);
		for(int j=0;j<m;++j) b[i][j+1]=(s[j]=='#');
	}
	for(int i=1;i<=n;++i) {
		for(int j=1;j<=m;++j) {
			if(b[i][j]){putchar('#');continue;}
			for(int k=1;k<=8;++k) ans[i][j]+=b[i+mvx[k]][j+mvy[k]];
			printf("%d",ans[i][j]);
		}
		putchar('\n');
	}
    return 0;
}