H, W = map(int, input().split())
S = ['.'*(W+2)] + ['.'+input()+'.'for _ in[0]*H] + ['.'*(W+2)]
cells = [[0] * W for _ in[0] * H]
for i in range(H):
    for j in range(W):
        if S[i+1][j+1] == '#':
            cells[i][j] = '#'
        else:
            surrounder = S[i][j:j+3] + S[i+1][j:j+3:2] + S[i+2][j:j+3]
            cells[i][j] = surrounder.count('#')
for x in cells:
    print(''.join(map(str, x)))