h,w = map(int,input().split())
l = [list(input()) for i in range(h)]
print(l)

def checknum(x,y):
    count = 0
    for i in range(-1,2):
        for j in range(-1,2):
            nx = x+i
            ny = y+j
            if 0 <= nx < h and 0 <= ny < w and l[nx][ny] == "#":
                count += 1
    return count

for i in range(h):
    for j in range(w):
        if l[i][j] == ".":
            l[i][j] = checknum(i,j)
for i in range(h):
    for j in range(w):
        print(l[i][j],end="")
    print()