dx=[-1,0,1,-1,1,-1,0,1]
dy=[-1,-1,-1,0,0,1,1,1]
h,w=map(int,input().split())
field = []
for i in range(h):
    field.append(list(input()))
print(field)

for y in range(h):
    for x in range(w):
        if field[y][x]=="#":
            continue
        cnt=0
        for k in range(8):
            nx=x+dx[k]
            ny=y+dy[k]
            if nx<0 or nx>=w or ny<0 or ny>=h:
                continue
            if field[ny][nx]=="#":
                cnt+=1
            field[y][x]=str(cnt)
for i in range(h):
    print("".join(field[i]))