h,w =map(int,input().split())
s = [input() for i in range(h)]
s_out =[]
for i in range(h):
    s_out.append("")

def mine(a):
    count = 0
    for i in range(len(a)):
        if a[i] == "#":
            count += 1
    return count

if h == 1 and w == 1:
    if s[0][0] == "#":
        print("#")
        sys.exit()
    else:
        print("0")
        sys.exit()

elif h==1:
    for j in range(w):
        if s[0][j] == "#":
            s_out[0] += "#"
        elif j == 0:
            s_out[0] += str(mine(s[0][1]))
        elif j == w-1:
            s_out[0] += str(mine(s[i][j-1]))
        else:
            s_out[0] += str(mine(s[i][j-1])+mine(s[i][j+1]))
    print(s_out[0])
    sys.exit()
    
elif w == 1:
    for i in range(h):
        if s[i][0] == "#":
            s_out[i] += "#"
        elif i == 0:
            s_out[i] += str(mine(s[1][0]))
        elif i == h-1:
            s_out[i] += str(mine(s[i-1][0]))
        else:
            s_out[i] += str(mine(s[i+1][0])+mine(s[i-1][0]))
    for i in s_out:
        print(i)
    sys.exit()

for i in range(h):
        for j in range(w):
            if s[i][j] == "#":
                s_out[i] += "#"
            elif i == 0 and j == 0:
                s_out[i] += str(mine(s[0][1])+mine(s[1][0:2]))
            elif i == 0 and j == w-1:
                s_out[i] += str(mine(s[i][j-1])+mine(s[i+1][j-1:j+1]))
            elif i == 0:
                s_out[i] += str(mine(s[i][j-1])+mine(s[i][j+1])+mine(s[i+1][j-1:j+2]))
            elif i == h-1 and j == 0:
                s_out[i] += str(mine(s[i-1][j:j+2])+mine(s[i][j+1]))
            elif i == h-1 and j == w-1:
                s_out[i] += str(mine(s[i-1][j-1:j+1])+mine(s[i][j-1]))
            elif i == h-1:
                s_out[i] += str(mine(s[i-1][j-1:j+2])+mine(s[i][j-1])+mine(s[i][j+1]))
            elif j == 0:
                s_out[i] += str(mine(s[i-1][j:j+2])+mine(s[i][j+1])+mine(s[i+1][j:j+2]))
            elif j == w-1:
                s_out[i] += str(mine(s[i-1][j-1:j+1])+mine(s[i][j-1])+mine(s[i+1][j-1:j+1]))
            else:
                s_out[i] += str(mine(s[i-1][j-1:j+2])+mine(s[i][j-1])+mine(s[i][j+1])+mine(s[i+1][j-1:j+2]))
for i in s_out:
    print(i)

### FIXED CODE ###

h,w =map(int,input().split())
s = [input() for i in range(h)]
s_out =[]

for i in range(h):
    s_out.append("")

def mine(a):
    count = 0
    for i in range(len(a)):
        if a[i] == "#":
            count += 1
    return count

if h == 1 and w == 1:
    if s[0][0] == "#":
        print("#")
        
    else:
        print("0")
        

elif h==1:
    for j in range(w):
        if s[0][j] == "#":
            s_out[0] += "#"
        elif j == 0:
            s_out[0] += str(mine(s[0][1]))
        elif j == w-1:
            s_out[0] += str(mine(s[i][j-1]))
        else:
            s_out[0] += str(mine(s[i][j-1])+mine(s[i][j+1]))
    print(s_out[0])
    
    
elif w == 1:
    for i in range(h):
        if s[i][0] == "#":
            s_out[i] += "#"
        elif i == 0:
            s_out[i] += str(mine(s[1][0]))
        elif i == h-1:
            s_out[i] += str(mine(s[i-1][0]))
        else:
            s_out[i] += str(mine(s[i+1][0])+mine(s[i-1][0]))
    for i in s_out:
        print(i)
    
else:
    for i in range(h):
            for j in range(w):
                if s[i][j] == "#":
                    s_out[i] += "#"
                elif i == 0 and j == 0:
                    s_out[i] += str(mine(s[0][1])+mine(s[1][0:2]))
                elif i == 0 and j == w-1:
                    s_out[i] += str(mine(s[i][j-1])+mine(s[i+1][j-1:j+1]))
                elif i == 0:
                    s_out[i] += str(mine(s[i][j-1])+mine(s[i][j+1])+mine(s[i+1][j-1:j+2]))
                elif i == h-1 and j == 0:
                    s_out[i] += str(mine(s[i-1][j:j+2])+mine(s[i][j+1]))
                elif i == h-1 and j == w-1:
                    s_out[i] += str(mine(s[i-1][j-1:j+1])+mine(s[i][j-1]))
                elif i == h-1:
                    s_out[i] += str(mine(s[i-1][j-1:j+2])+mine(s[i][j-1])+mine(s[i][j+1]))
                elif j == 0:
                    s_out[i] += str(mine(s[i-1][j:j+2])+mine(s[i][j+1])+mine(s[i+1][j:j+2]))
                elif j == w-1:
                    s_out[i] += str(mine(s[i-1][j-1:j+1])+mine(s[i][j-1])+mine(s[i+1][j-1:j+1]))
                else:
                    s_out[i] += str(mine(s[i-1][j-1:j+2])+mine(s[i][j-1])+mine(s[i][j+1])+mine(s[i+1][j-1:j+2]))
    for i in s_out:
        print(i)