function getLineByParam( param ){
  var ret;
  for ( var i=0; i<param[0].length; i++ ) {
    if ( "\n" == param[0].charAt( i ) ) {
      ret = param[0].slice( 0, i );
      param[0] = param[0].slice( ret.length+1 );
      return ret;
    }
  }
  ret = param[0];
  param[0]="";
  return ret;
}

function countBomb( S, i, j ){
  if ( '#' === S[i][j] ) return '#';
  var cnt = 0;
  if ( 0 < i ) {
    if ( 0 < j && '#' === S[i-1][j-1] ) cnt++;
    if ( '#' === S[i-1][j] ) cnt++;
    if ( S[i].length - 1 > j && '#' === S[i-1][j+1] ) cnt++;
  }
  if ( 0 < j && '#' === S[i][j-1] ) cnt++;
  if ( S[i].length - 1 > j && '#' === S[i][j+1] ) cnt++;
  if ( S.length - 1 > i ) {
    if ( 0 < j && '#' === S[i+1][j-1] ) cnt++;
    if ( '#' === S[i+1][j] ) cnt++;
    if ( S[i].length - 1 > j && '#' === S[i+1][j+1] ) cnt++;
  }
  return cnt;
}

function Main(input) {
  input = [input];
  var tmp = getLineByParam(input).split(" ");
  var H = parseInt( tmp[0] );
  var W = parseInt( tmp[1] );
  var S = [];
  for ( var i=0; i<H; i++ ) {
    S[i] = [];
    tmp = getLineByParam(input).split("");
    for ( var j=0; j<W; j++ ) {
      S[i][j] = tmp[j];
    }
  }

  for ( var i=0; i<H; i++ ) {
    for ( var j=0; j<W; j++ ) {
      S[i][j] = countBomb( S, i, j );
    }
    console.log( S[i].join("") );
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
