H, W = map(int, input().split())
H_lis = [str(input()) for _ in range(H)]

def check_bomb(i,j):
    try:
        if H_lis[i][j]==".":
            return 0
        elif H_lis[i][j]=="#":
            return 1
        else:
            return 0
    except:
        return 0

for i in range(H):
    ans = ""
    for j in range(W):
        if check_bomb(i,j)==1:
            ans += "#"
        else:
            ans+=str(check_bomb(i-1,j-1)+check_bomb(i-1,j)+check_bomb(i-1,j+1)+check_bomb(i,j-1)+check_bomb(i,j+1)+check_bomb(i+1,j-1)+check_bomb(i+1,j)+check_bomb(i+1,j+1))
    print(ans)
