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

from itertools import product
def num(i,j):
    c=0
    for p,q in product([-1,0,1],repeat=2):
        if 0<=i+p<H and 0<=j+q<W and S[i+p][j+q]=='#':
            c+=1
    return c

for i in range(H):
    for j in range(W):
        if S[i][j]=='.':
            S[i][j]=str(num(i,j))
    print(''.join(S[i]))
