h, w = map(int, input().split())
s = [input() for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            sum = 0
            for a in range(max(i-1, 0), min(i+2, h)):
                for b in range(max(j-1, 0), min(j+2, w)):
                    if s[a][b] == "#":
                        sum += 1
            print(sum, end="")
        else:
            print("#", end="")
    print()
