H, W = map(int, input().split())
T = [","*W + ",,"]  + ["," + input() + "," for _ in range(H)] + [","*W + ",,"]
ans = ""
d = [(-1, -1), (0, -1), (1, -1), (-1, 0), (1, 0), (-1, 1), (0, 1), (1, 1)]
for i in range(1, H+1):
    for j in range(1, W+1):
        if T[i][j] == "#":
            ans += "#"
        else:
            ans += str(sum(T[i+x][j+y] == "#" for x, y in d))
    ans += "\n"
print(ans)