program main
  implicit none
  integer :: h,w,i,j
  integer,allocatable :: x(:,:) 
  character(50) :: s,t
  character :: a

  read(*,*) h,w
  allocate(x(0:h+1,0:w+1))
  x(:,:)=0
  
  do i=1,h
     read(*,*) s

     do j=1,w
        if(s(j:j)=='#')then
           x(i,j)=-10
           x(i,j+1)=x(i,j+1)+1
           x(i,j-1)=x(i,j-1)+1
           x(i-1,j)=x(i-1,j)+1
           x(i-1,j+1)=x(i-1,j+1)+1
           x(i-1,j-1)=x(i-1,j-1)+1
           x(i+1,j)=x(i+1,j)+1
           x(i+1,j+1)=x(i+1,j+1)+1
           x(i+1,j-1)=x(i+1,j-1)+1
        endif
     enddo
  enddo
  
  do i=1,h
     t='0'
     do j=1,w
        if(x(i,j)<0)then
           t(j:j)='#'
        else
           write(a,'(i1)') x(i,j)
           t(j:j)=a
        endif
     enddo
     write(*,*) t
  enddo

end program main
        
        

     

  

