var toInt = x=>parseInt(x,10);
var toIntArr = arr=>arr.map(x=>toInt(x));
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

function Main(input){
	input = input.split('\n');
	var temp = input[0].split(' ');
	var h = toInt(temp[0]);
	var w = toInt(temp[1]);
	var ss = [];
	var ans = [];
	for(var i = 0; i < h; i++){
		ss[i] = input[i+1];
	}

	var mine = 0;
	for(var j = 0; j < h; j++){
		ans[j] = '';
		for(var k = 0; k < w; k++){
			if(ss[j][k] === '.'){
				mine = 0;
				if(j !== 0){
					if(k !== 0 && ss[j-1][k-1] === '#') mine++;
					if(ss[j-1][k] === '#') mine++;
					if(k !== w-1 && ss[j-1][k+1] === '#') mine++;
				}
				if(k !== 0 && ss[j][k-1] === '#') mine++;
				if(k !== w-1 && ss[j][k+1] === '#') mine++;
				if(j !== h-1){
					if(k !== 0 && ss[j+1][k-1] === '#') mine++;
					if(ss[j+1][k] === '#') mine++;
					if(k !== w-1 && ss[j+1][k+1] === '#') mine++;
				}
				ans[j] += String(mine);
			}else{
				ans[j] += '#';
			}
		}
	}

	ans.forEach(function(item,index,array){
		console.log(item);
	})
}

