h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
d = [-1, 0, 1]
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            total = 0
            for dy in d:
                for dx in d:
                    if 0<=i+dy<h and 0<=j+dx<w and s[i+dy][j+dx] == "#":
                        total += 1
            s[i][j] = str(total)
for i in range(h):
    print("".join(s[i]))
