'use strict'

function main(input) {
  const inputList = input.split('\n');
  const line1Array = inputList[0].split(' ')
  const h = Number(line1Array[0])
  const w = Number(line1Array[1])
  let s = inputList.slice(1)
  let tmp = new Array(h)

  for (let i=0; i<h; i++) {
    tmp[i] = new Array(w)
    tmp[i] = s[i].split('')
  }

  for (let i =0; i<h; i++) {
    for (let j=0; j<w; j++) {
      if (tmp[i][j] === '.') {
        tmp[i][j] = 0
        // console.log(String(isBomb(tmp, i, j)))
        if (isBomb(tmp, i-1, j-1)) tmp[i][j]++
        if (isBomb(tmp, i-1, j)) tmp[i][j]++
        if (isBomb(tmp, i-1, j+1)) tmp[i][j]++
        if (isBomb(tmp, i, j-1)) tmp[i][j]++
        if (isBomb(tmp, i, j+1)) tmp[i][j]++
        if (isBomb(tmp, i+1, j-1)) tmp[i][j]++
        if (isBomb(tmp, i+1, j)) tmp[i][j]++
        if (isBomb(tmp, i+1, j+1)) tmp[i][j]++
      }

 

    }
    s[i] = tmp[i].join('')
    console.log(s[i])
  }

}

function isBomb(array, i, j) {
  if (i < 0 || i >= array.length || j < 0 || j >= array[i].length) {
    return false 
  }

  if (array[i][j] === '#') {
    return true
  } else {
    return false
  }
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));