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

for row in range(H):
    for col in range(W):
        if S[row][col] == '#':
            continue
        else:
            if row == 0:
                if col == 0:
                    S[row][col] = [S[row][col+1], S[row+1][col], S[row+1][col+1]].count('#')
                elif col == W - 1:
                    S[row][col] = [S[row][col-1], S[row+1][col-1], S[row+1][col]].count('#')
                else:
                    S[row][col] = [S[row][col-1], S[row][col+1], S[row+1][col-1],
                               S[row+1][col], S[row+1][col+1]].count('#')
            elif row == H - 1:
                if col == 0:
                    S[row][col] = [S[row-1][col], S[row-1][col+1], S[row][col+1]].count('#')
                elif col == W - 1:
                    S[row][col] = [S[row-1][col-1], S[row-1][col], S[row][col-1]].count('#')
                else:
                    S[row][col] = [S[row-1][col-1], S[row-1][col], S[row-1][col+1],
                               S[row][col-1], S[row][col+1]].count('#')
            else:
                if col == 0:
                    S[row][col] = [S[row-1][col], S[row-1][col+1],
                                   S[row][col+1],
                                   S[row+1][col], S[row+1][col+1]].count('#')
                elif col == W - 1:
                    S[row][col] = [S[row-1][col-1], S[row-1][col],
                                   S[row][col-1], 
                                   S[row+1][col-1], S[row+1][col]].count('#')
                else:
                    S[row][col] = [S[row-1][col-1], S[row-1][col], S[row-1][col+1],
                                   S[row][col-1], S[row][col+1],
                                   S[row+1][col-1], S[row+1][col], S[row+1][col+1]].count('#')
for i in range(len(S)):
    print(*S[i])         