program prob3
    implicit none
    character(len=1), dimension(:, :), allocatable :: S
    integer :: H, W, i, j, tmp
    
    read(*,*) H, W
    allocate(S(H, W))
    do i = 1, H
        do j = 1, W
            read(*,'(a)',advance='no') S(i, j)
        end do
        read(*,*) 
    end do

    do i = 1, H
        do j = 1, W
            if(S(i, j) == '.') then
                tmp = 0
                if(i>=2) then
                    if(j>=2)then
                        if(S(i-1, j-1) == '#') then
                            tmp = tmp + 1
                        end if
                    end if
                    if(j<=W-1)then
                        if(S(i-1, j+1) == '#') then
                            tmp = tmp + 1
                        end if                       
                    end if
                    if(S(i-1, j) == '#') then
                        tmp = tmp + 1
                    end if
                end if
                if(i<=H-1) then
                    if(j>=2)then
                        if(S(i+1, j-1) == '#') then
                            tmp = tmp + 1
                        end if
                    end if
                    if(j<=W-1)then
                        if(S(i+1, j+1) == '#') then
                            tmp = tmp + 1
                        end if                       
                    end if
                    if(S(i+1, j) == '#') then
                        tmp = tmp + 1
                    end if
                end if
                if(j>=2)then
                    if(S(i, j-1) == '#') then
                        tmp = tmp + 1
                    end if
                end if
                if(j<=W-1)then
                    if(S(i, j+1) == '#') then
                        tmp = tmp + 1
                    end if                       
                end if
                S(i, j) = char(ichar('0') + tmp)
            end if
        end do
    end do
    
    do i = 1, H
        write(*,*) S(i, :)
    end do

    stop
contains
end program prob3