program name
    implicit none
    character(1),allocatable:: s(:,:)
    integer(4),allocatable:: num(:,:)
    integer(4):: h,w,i,j, dj,di

    read*, h,w
    allocate(s(w,h), num(0:w+1,0:h+1))
    num(:,:) = 0
    block
        character(w):: inpt_s
        do i=1,h
            read*, inpt_s
            do j=1,w
                s(j,i) = inpt_s(j:j)
                if (s(j,i) == '#') then
                    do di = -1,1
                        do dj = -1,1
                            if (di==0 .and. dj==0) cycle
                            num(j+dj,i+di) = num(j+dj,i+di) + 1
                        end do
                    end do
                end if
            end do
        end do
    end block

    do i=1,h
        do j=1,w
            if (s(j,i) == '.') s(j,i) = char(num(j,i) + ichar('0'))
        end do
        print'(a)', s(:,i)
    end do
end program name