program main
	integer H, W, i, j, k, l, counter
	character(1), allocatable :: S(:, :), Sans(:, :)
	read(*, *) H, W
	allocate(S(0:H+1, 0:W+1))
	allocate(Sans(1:H, 1:W))
	S(0, 0:W+1) = '.'
	S(H+1, 0:W+1) = '.'
	S(1:H, 0) = '.'
	S(1:H, W+1) = '.'
	do i = 1, H
		do j = 1, W-1
			read(*, '(a1)', advance = 'No') S(i, j)
		end do
		j = W
		read(*, '(a1)') S(i, j)
	end do
	do i = 1, H
		do j = 1, W
			if(S(i, j) == '.') then
				counter = 0
				do k = -1, 1 
					do l = -1, 1
						if(S(i+k, j+l) == '#') then
							counter = counter + 1
						end if
					end do
				end do
				write(Sans(i, j), '(I1)') counter
			else 
				write(Sans(i, j), '(a1)') '#'
			end if
		end do
	end do
	do i = 1, H
		do j = 1, W-1
			write(*, '(a1)', advance = 'No') Sans(i, j)
		end do
		j = W
		write(*, '(a1)') Sans(i, j)
	end do		
end program main