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

dx = [-1,0,1]
dy = [-1,0,1]

for i in range(h):
    for j in range(w):
        if S[i][j] == '#':
            continue

        count = 0
        for x in dx:
            for y in dy:
                if 0<=i+y<h and 0<=j+x<w and S[i+y][j+x]=='#':
                    count += 1
        S[i][j] = str(count)

for s in S:
    print("".join(s))