h,w=io.read("*n","*n","*l")
s={}
for i=1,h+2 do
    s[i]={}
    if i~=1 and i~=h+2 then
        x=io.read()
    end
    for j=1,w+2 do
        if i==1 or i==h+2 then
            s[i][j]="."
        else
            if j==1 or j==w+2 then
                s[i][j]="."
            else
                s[i][j]=x:sub(j-1,j-1)
            end
        end
    end
end

for i=2,h+1 do
    for j=2,w+1 do
        if s[i][j]=="." then
            bom_counter=0
            for k=i-1,i+1 do
                for l=j-1,j+1 do
                    if s[k][l]=="#" then
                        bom_counter=bom_counter+1
                    end
                end
            end
            s[i][j]=bom_counter
        end
    end
end

for i=2,h+1 do
    print(table.concat(s[i],"",2,w+1))
end