#include<bits/stdc++.h>
using namespace std;
long long h,w,i,j,k,b[55][55];
char a[55][55];
int main(){
	cin>>h>>w;
	for(int i=1;i<=h;++i){
		for(int j=1;j<=w;++j){
			cin>>a[i][j];
			if(a[i][j]=='#'){
				b[i-1][j]++;
				b[i-1][j-1]++;
				b[i-1][j+1]++;
				b[i][j-1]++;
				b[i][j+1]++;
				b[i+1][j]++;
				b[i+1][j+1]++;
				b[i+1][j-1]++;
			}
		}
	}
	for(int i=1;i<=h;++i){
		for(int j=1;j<=w;++j){
			if(a[i][j]!='#'){
				cout<<b[i][j];
			}
			else cout<<a[i][j];
		}
		cout<<endl;
	}
	return 0;
} 
