local h, w = io.read("*n", "*n", "*l")
local t = {}
for i = 1, (w + 2) * (h + 2) do t[i] = "." end
for i = 2, h + 1 do
  local s = io.read()
  for j = 2, w + 1 do
    t[(i - 1) * (w + 2) + j] = s:sub(j - 1, j - 1)
  end
end
for i = 2, h + 1 do
  for j = 2, w + 1 do
    local idx = (i - 1) * (w + 2) + j
    if t[idx] == "." then
      local cnt = 0
      local lis = {- w - 3, -w - 2, -w  - 1, -1, 1, w + 1, w + 2, w + 3}
      for k = 1, #lis do
        if t[idx + lis[k]] == "#" then
          cnt = cnt + 1
        end
      end
      io.write(cnt)
    else
      io.write("#")
    end
  end
  io.write("\n")
end
