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

d = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            cnt = 0
            for r in range(8):
                x = i + d[r][0]
                y = j + d[r][1]
                if 0 <= x < W and 0 <= y < H and S[x][y] == '#':
                    cnt = cnt + 1
            S[i][j] = str(cnt)

for i in range(H):
    print(''.join(S[i]))
