function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main(input) {
  input = myconv(input,3);
  var H = myconv(input[0],4)[0];
  var W = myconv(input[0],4)[1];
  input.shift();
  for(var i = 0; i < H; i++){
    input[i] = myconv(input[i],6);
  }
  for(var i = 0; i < H; i++){
    for(var j = 0; j < W; j++){
      if(input[i][j] == "."){
        //123
        //4.5
        //678
        var count = 0;
        try{
        var hidariue = input[i-1][j-1];
        if(hidariue == "#"){count++;}
        }catch(e){}
        try{
        var ue = input[i-1][j];
        if(ue == "#"){count++;}
        }catch(e){}
        try{
        var migiue = input[i-1][j+1];
        if(migiue == "#"){count++;}
          }catch(e){}
        try{
        var hidari = input[i][j-1];
        if(hidari == "#"){count++;}
          }catch(e){}
        try{
        var migi = input[i][j+1];
        if(migi == "#"){count++;}
          }catch(e){}
        try{
        var hidarishita = input[i+1][j-1];
        if(hidarishita == "#"){count++;}
          }catch(e){}
        try{
        var shita = input[i+1][j];
        if(shita == "#"){count++;}
          }catch(e){}
        try{
        var migishita = input[i+1][j+1];
        if(migishita == "#"){count++;}
          }catch(e){}
        input[i][j] = count;
      }
    }
  }
  for(var i = 0; i < H; i++){
    input[i] = input[i].join("");
  }
  myout(input.join("\n"));
}

Main(myin());
