(function() {
    'use strict';
 
    var lines = [];
    require('readline').createInterface({
      input: process.stdin,
      output: process.stdout
    }).on('line', function(line) {
      lines.push(line);
    });
    process.stdin.on('end', function() {
      //lines.forEach(function(line) {
        //var tokens = line.split(' ').map(Number);
        //    console.log(tokens[0] + ' ' + tokens[1]);
      //}
      //)
      ;
      
    // ToDo start
      var inputLine = lines[0].split(" ")
      var tate = inputLine[0]
      var yoko = inputLine[1]
      var anslines = []
    
        for(var i=0;i<tate;i++){
            anslines[i]=""

            for( var j=0;j<yoko;j++){
                if( lines[i+1][j] == "."){
                  var cnt =0
                  for(var tmpi=Math.max(i,0);tmpi<=Math.min(i+2,tate);tmpi++ ){
                      for(var tmpj=Math.max(j-1,0);tmpj<=Math.min(j+1,yoko);tmpj++){
                          if(lines[tmpi][tmpj]=="#"){
                              cnt++
                          }
                      }
                  }
//                  console.log("cnt:" + cnt)
                  anslines[i]= anslines[i]+cnt.toString()
              }else{
                anslines[i] = anslines[i] + "#"
//                console.log("cnt:" + "#")
              }
            }
        }
        for(var i=0;i<tate;i++){
            console.log(anslines[i])
        }
        
    // ToDo end

    });

    
})();
  
  