#include<bits/stdc++.h>
using namespace std;
char ch[51][51];
bool a[51][51];
int h,w;
int main(){
	cin>>h>>w;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
		    cin>>ch[i][j];
		    a[i][j]=ch[i][j]=='#'? 1:0;
		}
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(a[i][j])cout<<"#";
			else cout<<a[i-1][j]+a[i+1][j]+a[i][j+1]+a[i][j-1]+a[i-1][j-1]+a[i-1][j+1]+a[i+1][j-1]+a[i+1][j+1];
		}
		cout<<endl;
	}
	return 0;
}