#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;

const int maxn=1e3+10,dx[]={1,1,1,0,-1,-1,-1,0},dy[]={1,0,-1,-1,-1,0,1,1};
int n,m;
char s[maxn][maxn];

int main(){
	cin>>n>>m;
	for(int i=1;i<=n;++i)
		cin>>(s[i]+1);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			if(s[i][j]=='.'){
				s[i][j]='0';
				for(int d=0;d<8;++d)
					if(s[i+dx[d]][j+dy[d]]=='#')
						++s[i][j];
			}
	for(int i=1;i<=n;++i)
		cout<<(s[i]+1)<<endl;
	return 0;
}