H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            S[i][j] = str(
                sum(S[x][y] == '#'
                    for x in range(max(0, i - 1), min(H, i + 2))
                    for y in range(max(0, j - 1), min(W, j + 2))
                )
            )
for s in S:
    print(''.join(s))