H, W = map(int, input().split(' '))
maps = [list('.'+input()+'.') for _ in range(H)]
maps = [['.'] * (W+2)] + maps + [['.'] * (W+2)]

for i in range(1, H+1):
    for j in range(1, W+1):
        if maps[i][j] == '.':
            maps[i][j] = (maps[i-1][j-1:j+2] + maps[i][j-1:j+2] + maps[i+1][j-1:j+2]).count('#')
maps.pop(0)
maps.pop(H)
for i in maps:
    print(''.join(map(str, i[1:-1])))