let buf = '';
process.stdin.setEncoding('utf8');
process.stdin.on('readable', () => {
  let s = process.stdin.read();
  if (s !== null) { buf += s.toString(); }
});
process.stdin.on('end', () => {
  let lines = buf.trim().split("\n");
  let [h, w] = lines[0].split(' ').map( (x) => parseInt(x) );
  let field: number[][] = [];
  for (let i = 0; i < h; i++) {
    field[i] = [];
    for (let j = 0; j < w; j++) {
      field[i][j] = 0;
    }
  }
  for (let i = 0; i < h; i++) {
    for (let j = 0; j < w; j++) {
      if (lines[i+1][j] === '#') {
        field[i][j] = -99;
        if (i   > 0) { field[i-1][j]++; }
        if (i+1 < h) { field[i+1][j]++; }
        if (j   > 0) { field[i][j-1]++; }
        if (j+1 < w) { field[i][j+1]++; }
      }
    }
  }
  for (let i = 0; i < h; i++) {
    let s = '';
    for (let j = 0; j < w; j++) {
      if (field[i][j] < 0) {
        s += '#';
      } else {
        s += field[i][j].toString();
      }
    }
    console.log(s);
  }
});