"use strict"
function Main(input){
    input = input.split("\n");
    var tmp = input[0].split(" ");

    var H = parseInt(tmp[0],10);
    var W = parseInt(tmp[1],10);

    var output = "";

    //配列作成
    var tbl = new Array(H + 2);
    var tbl1  = new Array(H + 2);
    for(let y = 0;  y < H + 2; y++) {
      tbl[y] = new Array(W + 2).fill(0);
      tbl1[y] = new Array(W + 2).fill(0);
    }
    
    for(let y = 0;  y < H ; y++) {
        var tmp1 = input[y + 1].split("");
        for (let x = 0; x < W; x++) {

            if (tmp1[x] != "#"){
                tbl[y + 1][x + 1] = 0;
            }else{
                tbl[y + 1][x + 1] = 1;
                tbl1[y + 1][x + 1] = "#";
            }
        }
    }
    //console.log(tbl1);

    for(let i = 0; i < H; i++){
        for(let j = 0; j < W; j++){
            if (tbl[i + 1][j + 1] != 1){
                //爆弾の数を計算                              
                tbl1[i + 1][j + 1] = tbl[i][j] + tbl[i][j + 1] + tbl[i][j + 2] + tbl[i + 1][j] + tbl[i + 1][j + 2]  + tbl[i + 2][j] + tbl[i + 2][j + 1] + tbl[i + 2][j + 2];
                output += tbl1[i + 1][j + 1];
            }else {
                output += tbl1[i + 1][j + 1];
            }
        }
        output += "\n";
    }
    console.log(output);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));