import Foundation
func toTuple<T>(_ args: [T]) -> (T, T) { (args[0], args[1]) }
func readInts() -> [Int] { readLine()!.split(separator: " ").map { Int($0)! } }

let (h, w) = toTuple(readInts())
var si: [[String]] = []
for _ in 0..<h {
  let s = readLine()!.map { String($0) }
  si.append(s)
}
var ans: [[String]] = []
for i in 0..<h {
  var row: [String] = []
  for j in 0..<w {
    guard si[i][j] != "#" else {
      row.append("#")
      continue
    }
    var count = 0
    if i - 1 >= 0 , j - 1 >= 0 , si[i-1][j-1] == "#" {
      count += 1
    }
    if i - 1 >= 0 , si[i-1][j] == "#" {
      count += 1
    }
    if i - 1 >= 0 , j + 1 < w , si[i-1][j+1] == "#" {
      count += 1
    }
    if j + 1 < w , si[i][j+1] == "#" {
      count += 1
    }
    if i + 1 < h , j + 1 < w , si[i+1][j+1] == "#" {
      count += 1
    }
    if i + 1 < h , si[i+1][j] == "#" {
      count += 1
    }
    if i + 1 < h , j - 1 >= 0 , si[i+1][j-1] == "#" {
      count += 1
    }
    if j - 1 >= 0 , si[i][j-1] == "#" {
      count += 1
    }
    row.append(String(count))
  }
  ans.append(row)
}
ans.forEach {
  print($0.joined())
}