#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
char a[55][55];
int n,m,ans;
using namespace std;
int bomb(int x,int y){
	ans=0;
	for(int i=x-1;i<=x+1;i++){
		for(int j=y-1;j<=y+1;j++){
			if(i==x&&j==y) continue;
			if(a[i][j]=='#') ans++;
		}
	}
    return ans;
}
int main(){
	cin>>n>>m;;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(a[i][j]=='.'){
				cout<<bomb(i,j);
			}else{
				cout<<'#';
			}
		}
		cout<<endl;
	}
	return 0;
}
