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

d=[[-1,-1],[-1,0],[0,-1],[1,0],[-1,1],[0,1],[1,1],[1,-1]]
for i in range(H):
    for j in range(W):
        if S[i][j]=='.':
            cnt=0
            for k in d:
                nx,ny=i-k[0],j-k[1]
                if 0<=nx<H and 0<=ny<W and S[nx][ny]=='#':
                    cnt+=1
            S[i][j]=str(cnt)
for s in S:
    print(''.join(s))