H, W = map(int, input().split())
S = [list(input()) for i in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        tmp = 0
        for di in range(max(i-1, 0), min(i+2, H)):
            for dj in range(max(j-1, 0), min(j+2, W)):
                tmp += int(S[di][dj] == '#')
        S[i][j] = str(tmp)

for si in S:
    print(''.join(si))
    