function main(input) {
  var H = input[0].split(" ")[0]-0;
  var W = input[0].split(" ")[1]-0;
  var map = [];
  for(var i=1;i<=H;i++){
    map[i-1] = input[i].split("");
  }
  for(var i=0;i<H;i++){
    for(var j=0;j<W;j++){
      if(map[i][j]=="."){
        var cnt = 0;
        for(var x=-1;x<=1;x++){
          for(var y=-1;y<=1;y++){
            if(map[x+i] && map[x+i][y+j] == "#") cnt++;
          }
        }
        map[i][j]=cnt;
      }
    }
  }
  console.log(map.map(v=>v.join("")).join("\n"));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))
