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

  do i = 1, h
     do j = 1, w
        call bombcount(s, i, j, h, w, ans)
     end do
  end do

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


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

    if (s(i)(j:j) == '#' ) then
       write(ans(i)(j:j),'(a)') '#'
       return
    end if
    
    c = 0
    do a = j-1, j+1
       if (i == 1) then
          exit
       else if (a == 0) then
          cycle
       else if ( a == w+1 ) then
          exit
       else
          if (s(i-1)(a:a) == '#' ) then
             c = c + 1
          end if
       end if
    end do

    if ( j /= 1 ) then
       if (s(i)(j-1:j-1) == '#' ) then
          c = c + 1
       end if
    end if
    
    if ( j /= w ) then
       if (s(i)(j+1:j+1) == '#' ) then
          c = c + 1 
       end if
    end if
    
    do a = j-1, j+1
       if (i == h) then
          exit
       else if (a == 0) then
          cycle
       else if ( a == w+1 ) then
          exit
       else
          if (s(i+1)(a:a) == '#' ) then
             c = c + 1
          end if
       end if
    end do

    write(ans(i)(j:j),'(i1)') c
    
    return
  end subroutine bombcount
end program bomb
