r, c = map(int, input().split())
d = [list(input()) for i in range(r)]
bom = [(x,y) for (x,i) in enumerate(d) for (y,j) in enumerate(i) if j == '#']
temp = []
for b in bom:
    temp += [(b[0]+x, b[1]+y) for y in [1,0,-1] for x in [1,0,-1]]
print('\n'.join([''.join([str(temp.count((i,j))) if d[i][j] != '#' else '#' for j in range(c)]) for i in range(r)]))