H, W = map(int, raw_input().split())
grid = [raw_input() for r in range(H)]
for r in range(H):
    line = ""
    for c in range(W):
        if grid[r][c] == "#":
            line += "#"
        else:
            cnt = 0
            for dr in range(-1, 2):
                for dc in range(-1, 2):
                    nr, nc = r+dr, c+dc
                    if (0 <= nr < H) and (0 <= nc < W) and (grid[nr][nc] == "#"):
                        cnt += 1
            line += str(cnt)
    print line