program bomb
  implicit none
  integer :: h, w, i, c, j
  character(len=50), allocatable :: s(:), ans(:)
  
  read(*,*) h, w
  allocate(s(h),ans(h))
  do i = 1, h
     read(*,*) s(i)
  end do

  call bombcount(s, h, w, ans)

  do i = 1, h
     write(*,'(a)') trim(ans(i))
  end do
  deallocate(s, ans)

  stop
contains
  
  subroutine bombcount(s, h, w, ans)
    implicit none
    character(len=50) :: s(h), ans(h)
    integer :: i, j, h, w, num(0:h+1,0:w+1)
    integer :: a, c

    num = 0
    do i = 1, h
       do j = 1, w
          ans(i)(j:j) = '0'
       end do
    end do

    do i = 1, h
       do j = 1, w
          if ( s(i)(j:j) == '#' ) then
             do a = i-1, i+1
                do c = j-1, j+1
                   num(a,c) = num(a,c) + 1
                end do
             end do
          end if
       end do
    end do

    do i = 1, h
       do j = 1, w
          if ( s(i)(j:j) == '#' ) then
             write(ans(i)(j:j),'(a)') '#'
          else
             write(ans(i)(j:j),'(i1)') num(i,j)
          end if
       end do
    end do
    
  end subroutine bombcount
end program bomb
