#include <iostream>
#include <string>

using namespace std;

int main(){
	int H, W;
	cin >> H >> W;
	string T[50];
	const int dx[8] = {1,0,-1,0,1,-1,-1,1}
	const int dy[8] = {0,1,0,-1,1,1,-1,-1}
	for(i=0; i<H; ++i){
		cin >> T[i];
	}
	for(i=0; i<H; ++i){
		for(j=0; j<W; ++j){
			int count = 0;
			if(T[i][j]=="."){
				for(int n=0; n<8; ++n){
					const int ni = i + dy[n];
					const int nj = j + dx[n];
					if(ni<0 or H<=ni) continue;
					if(nj<0 or W<=nj) continue;
					if(T[ni][nj] == "#") count++;
				}
				T[i][j]=char(count+0)
			}else{
				T[i][j]="#"
			}
		}
	}
	for (int i=0; i<H; ++i) cout << T[i] << endl;
	return 0;
}