program main
  implicit none
  integer :: w, h, i, j, cnt
  character(50) :: l
  character(1), allocatable :: s(:, :)
  read(*, *) h, w
  allocate(s(0:w + 1, 0:h + 1))

  s(:, :) = "."
  do i = 1, h
    read(*, *) l
    do j = 1, w
      s(j, i) = l(j:j)
    end do
  end do

  do i = 1, h
    do j = 1, w
      if (s(j, i) /= "#") then
        cnt = 0
        if (s(j - 1, i - 1) == "#") cnt = cnt + 1
        if (s(j - 1, i    ) == "#") cnt = cnt + 1
        if (s(j - 1, i + 1) == "#") cnt = cnt + 1
        if (s(j    , i - 1) == "#") cnt = cnt + 1
        if (s(j    , i + 1) == "#") cnt = cnt + 1
        if (s(j + 1, i - 1) == "#") cnt = cnt + 1
        if (s(j + 1, i    ) == "#") cnt = cnt + 1
        if (s(j + 1, i + 1) == "#") cnt = cnt + 1
        write(s(j, i), "(i0)") cnt
      end if
    end do
  end do

  l = ''
  do i = 1, h
    do j = 1, w
      l(j:j) = s(j, i)
    end do
    write(*, "(a)") trim(l)
  end do
end program main
